Convert GMT DateTime to EST DateTime (and vice versa)

Hi,

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).

Additionally.
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

x
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:
https://msdn.microsoft.com/en-us/library/vstudio/az4se3k1(v=vs.100).aspx

To convert to UTC format:
https://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime(v=vs.110).aspx

To convert to local time:
https://msdn.microsoft.com/en-us/library/system.datetime.tolocaltime(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/bb397769(v=vs.110).aspx

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
it_saigeDeveloperCommented:
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()
		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())
		Console.ReadLine()
	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.