This works:

1
2
3
4
    let now = DateTime.Now.ToUniversalTime()
    let est = System.TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"
    let offset = est.GetUtcOffset now
    let estTime = now.AddHours offset.TotalHours

but you need to be compiling for .NET 3.5 or greater, or

1
TimeZoneInfo

won't be defined I think. And I think FSI goes to .NET 2.0 by default (at least on my machine), so that may be the source of your issues.

By on 2/22/2010 7:08 AM ()

Hi, Mau:
Thank you very much for your input.
The following code works:
> open System
let now = DateTime.Now.ToUniversalTime()
let est = System.TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"
let offset = est.GetUtcOffset now
let estTime = now.AddHours offset.TotalHours;;

val now : DateTime = 2/25/2010 7:18:33 PM
val est : TimeZoneInfo = (UTC-05:00) Eastern Time (US & Canada)
val offset : TimeSpan = -05:00:00
val estTime : DateTime = 2/25/2010 2:18:33 PM

I have to use open System in F# Interactive, otherwise, I got a lot of warnings.
Thank you very much for your help.

By on 2/25/2010 11:19 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper