How do I format DateTime or TimeZone / TimeZoneInfo to display three letters?

I'm working with a BOM that requires a specific Datetime format that I didn't necessarily have to work with.

During the OFT process (1 not 2) the date-time should be printed (DTCLIENT or DTSERVER) in this format:
  +20071015021529,000

however the examples show:

20071015021529.000[-8:PST]    

      

I have no problem with the first one using the instruction

DateTime.Now.ToString("yyyyMMddHHmmss.fff")

      

I can even figure out how to get %z

to get the correct offset.

The three alphabetic timezone codes are where I worked. Is there an easy way to get this in .net, or am I going to finish writing the code to output and parse what I need?

+2


source to share


3 answers


You need to figure out exactly what 3-letter codes he needs. For example, what to give Europe/Paris

? Personally, I would convert the data to UTC and format it that way, unless you really need to store the timezone information.



+2


source


Three-letter time zone codes are not unique across countries and are not fully standardized. For example, "CST" can be an acronym for US Central Standard Time or China Standard Time. Which is correct depends on your locale.

As far as I know, there is no functionality in the .NET Framework to find such codes, so you will need to implement it yourself.



Also (but you probably know this), you need to be careful how you implement this feature. There is not necessarily a one-to-one correspondence between UTC offsets and time zone codes. For example, UTC-0700 can be either Mountain Standard Time (MST) or US Pacific Daylight Time (PDT).

+5


source


If you use r, it will provide you with RFC format. This will help you.

String.Format("{0:r}", dt);  // "Sun, 09 Mar 2008 16:05:07 GMT"   RFC1123

      

You can also check this SO> link if it can help you.

+4


source







All Articles