0

I am trying to convert strings to dates in the format below. I would like to keep the timezone format such that when i retrieve it from the DB it will be parsed to the correct time.

Another example of the string i receive is "19 March 2014 10:32:04 GMT";

`string date = "19 March 2014 10:32:04 CEST";
 Console.WriteLine(date);
 DateTimeOffset result = DateTime.ParseExact(date, "dd MMMM yyyy HH:mm:ss Z",
            CultureInfo.InvariantCulture);' `

This is for a .net API

Thanks

Dan

Dan
  • 1,447
  • 2
  • 14
  • 30
  • http://stackoverflow.com/questions/19879817/c-sharp-parse-gmt-date-string-to-datetime – Habib Apr 04 '14 at 16:30
  • and a more detailed explanation of why your plan is flawed, from a man who knows, http://stackoverflow.com/questions/4195948/windows-time-zone-abbreviations-in-asp-net – Jodrell Apr 04 '14 at 16:33

1 Answers1

0

The quick answer is, you can't do it.


Here is why,

There is a definitive database of world timezones, you can get it from the IANA here.

The problem is, the 3 or 4 letter abbreviations have a many-to-one association with the IANA timezones. For instance "AMT" means different things, depending on your culture or what part of the world you are in.

AMT "Armenia Time Asia"         UTC + 4 hours 
AMT "Amazon Time South America" UTC - 4 hours 

If you really want to tackle this, I suggest using Noda Time to represent your Instances. You'll have to write some code to convert the abbreviations to a standard IANA timezone.

We can't do this for you, it depends on the context of your application.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
  • Thanks for your comments. Basically i am parsing an email body and this is the format for the date. Unfortunately i have no control over the format. I can save the information to the date fine however without the timezone information our mobile apps that's consume the date through the api are unable to show correct time – Dan Apr 04 '14 at 21:26
  • @Dan perhaps you can map the timezone abbreviations in the supplied data one-to-one with a subset of IANA timezones. – Jodrell Apr 07 '14 at 08:17