2 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
DateTimetype 不知道時(shí)區(qū),它知道的關(guān)于時(shí)區(qū)的一切都是 a DateTimeKind,可以是Local,Utc或Unspecified。包含在字符串表示中的區(qū)域信息將基于Kind值和服務(wù)器時(shí)區(qū)。
您應(yīng)該DateTimeOffset在您的場(chǎng)景中使用,該場(chǎng)景將日期時(shí)間和時(shí)區(qū)信息存儲(chǔ)在一個(gè)值中:
var dateTime = DateTime.Now; /*your date time here*/
var destinationTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var zonedDateTime = new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified), destinationTimeZone.BaseUtcOffset);
var dateTimeStr = zonedDateTime.ToString("o"/*your format goes here*/);
- 2 回答
- 0 關(guān)注
- 177 瀏覽
添加回答
舉報(bào)