ayilmaz ayilmaz - 1 year ago 201
C# Question

Convert timezone specific datetime string to datetime in C#

How can I convert

Tue, 01 Nov 2016 02:00 PM EET
datetime string to
in C#? What is a good practice to do it?

Answer Source

By replacing timezone abbreviation with zone offset you can convert using DateTime.ParseExact

string date = "Tue, 01 Nov 2016 02:00 PM EET";
DateTime dt = DateTime.ParseExact(date.Replace("EET", "+2"), "ddd, dd MMM yyyy hh:mm tt z", CultureInfo.InvariantCulture);

and if you want more safer way by checking exception then you can using DateTime.TryParseExact method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download