How to set a time zone (or a Kind) of a DateTime value?

前端 未结 3 425
-上瘾入骨i
-上瘾入骨i 2020-12-29 18:15

I mean to store strict UTC time in a DateTime variable and output it in ISO 8601 format.

To do the last I\'ve used .ToString(\"yyyy-MM-ddTHH:mm:sszzz\"), and it has

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 18:32

    You can try this as well, it is easy to implement

    TimeZone time2 = TimeZone.CurrentTimeZone;
    DateTime test = time2.ToUniversalTime(DateTime.Now);
    var singapore = TimeZoneInfo.FindSystemTimeZoneById("Singapore Standard Time");
    var singaporetime = TimeZoneInfo.ConvertTimeFromUtc(test, singapore);
    

    Change the text to which standard time you want to change.

    Use TimeZone feature of C# to implement.

提交回复
热议问题