Where's the DateTime 'Z' format specifier?

后端 未结 6 1427
抹茶落季
抹茶落季 2020-11-27 06:09

[Update: Format specifiers are not the same thing as format strings; a format specifier is a piece of a custom format string, where a format string is \

6条回答
  •  爱一瞬间的悲伤
    2020-11-27 06:53

    Label1.Text = dt.ToString("dd MMM yyyy | hh:mm | ff | zzz | zz | z");
    

    will output:

    07 Mai 2009 | 08:16 | 13 | +02:00 | +02 | +2
    

    I'm in Denmark, my Offset from GMT is +2 hours, witch is correct.

    if you need to get the CLIENT Offset, I recommend that you check a little trick that I did. The Page is in a Server in UK where GMT is +00:00 and, as you can see you will get your local GMT Offset.


    Regarding you comment, I did:

    DateTime dt1 = DateTime.Now;
    DateTime dt2 = dt1.ToUniversalTime();
    
    Label1.Text = dt1.ToString("dd MMM yyyy | hh:mm | ff | zzz | zz | z");
    Label2.Text = dt2.ToString("dd MMM yyyy | hh:mm | FF | ZZZ | ZZ | Z");
    

    and I get this:

    07 Mai 2009 | 08:24 | 14 | +02:00 | +02 | +2
    07 Mai 2009 | 06:24 | 14 | ZZZ | ZZ | Z 
    

    I get no Exception, just ... it does nothing with capital Z :(

    I'm sorry, but am I missing something?


    Reading carefully the MSDN on Custom Date and Time Format Strings

    there is no support for uppercase 'Z'.

提交回复
热议问题