Parse DateTime with time zone of form PST/CEST/UTC/etc

前端 未结 6 852
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:28

I\'m trying to parse an international datetime string similar to:

24-okt-08 21:09:06 CEST

So far I\'ve got something like:

         


        
6条回答
  •  暖寄归人
    2020-11-22 04:47

    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, what part of the world you are in and the context of your application.

    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.


    Another good example is "CST".

    CST "China Standard Time"   Asia            UTC + 8 hours 
    CST "Central Standard Time" Central America UTC - 6 hours 
    CST "Cuba Standard Time"    Caribbean       UTC - 5 hours 
    CST "Central Standard Time" North America   UTC - 6 hours 
    

提交回复
热议问题