vendredi 18 avril 2014

ASP.net - chaîne c# Parse à ce jour dans le format suivant 19 mars 2014 10:32:04 CEST - Stack Overflow



This question already has an answer here:




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




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.




This question already has an answer here:




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



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.


0 commentaires:

Enregistrer un commentaire