C# Datetimes: Conversion for different time zones

前端 未结 6 777
[愿得一人]
[愿得一人] 2020-12-01 19:06

I have a bunch of date times that I keep track of for my app. They are all in UTC time. For part of my app I want to send an email with one of these times, but edited to be

6条回答
  •  猫巷女王i
    2020-12-01 19:33

        var now = DateTime.Now; // Current date/time
        var utcNow = now.ToUniversalTime(); // Converted utc time
        var otherTimezone = TimeZoneInfo.FindSystemTimeZoneById("ANY OTHER VALID TIMEZONE"); // Get other timezone
        var newTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, otherTimezone); // New Timezone
    

提交回复
热议问题