C# 本地时间转换为utc时间并显示

Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));

输出 2022-09-28T08:17:12.455Z

附录:https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

https://stackoverflow.com/questions/3323113/datetime-to-string-with-time-zone

posted @ 2022-09-28 16:19  nil  阅读(192)  评论(0编辑  收藏  举报