Convert GMT DateTime to EST DateTime (and vice versa)


VB.Net Framework 4.0 question...

1 - I need to convert a string value such as this "2005-09-01T04:00:00.000000Z" which is GMT(Zulu) time to a DateTime object that represents the corresponding Date and Time in Eastern Standard Time (irrespective of the PC's time zone which this subroutine would run on).  The resultant EST Date and Time value must be adjusted for Daylight savings time if in effect or just EST if not (you get my meaning).

2 - Similar and somewhat conversely to the above, I also need to convert a string value such as this "2005/01/19 16:30" which would represent an EST Date and Time value to a GMT string value such as "2005-01-19T21:30:00.000000Z"

I read the MSDN article on this but my development PC is on MST and fouls up the results.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Easwaran ParamasivamCommented:
Simply, while saving the time somewhere such as DB use UTC format. While retrieving back convert to Local time.

Please refer the datetime available formats:

To convert to UTC format:

To convert to local time:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
In other words:
Imports System.Globalization

Module Module1
	ReadOnly zuluString = "2005-09-01T04:00:00.000000Z"
	ReadOnly localString = "2005/01/19 16:30"

	Sub Main()
		Dim utc As DateTime
		Dim local As DateTime

		Dim provider As CultureInfo = CultureInfo.CurrentCulture
		utc = DateTime.Parse(zuluString, provider, DateTimeStyles.AssumeUniversal).ToUniversalTime()
		local = DateTime.Parse(localString, provider, DateTimeStyles.AssumeLocal).ToLocalTime()

		Console.WriteLine("First let's retrieve our local time from the GMT (Zulu) string")
		utc = DateTime.SpecifyKind(utc, DateTimeKind.Unspecified)
		Console.WriteLine("GMT: {0:s}", utc)
		Console.WriteLine("EST: {0:s}", TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utc, "Eastern Standard Time"))
		Console.WriteLine("Local: {0:s}", utc.ToLocalTime())

		Console.WriteLine("Now let's retrieve our GMT (Zulu) from our local time string")
		Console.WriteLine("Local: {0:s}", local)
		Console.WriteLine("EST: {0:s}", TimeZoneInfo.ConvertTimeBySystemTimeZoneId(local, "Eastern Standard Time"))
		Console.WriteLine("GMT: {0:s}", local.ToUniversalTime())
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.