[英]convert UTC date string to local dateTime
我需要將 UTC dateTime 轉換為本地我已嘗試解析但無法這樣做?
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("UTC DateTime Convertor....!");
var giveDateTime = "22-06-2021T14:10:45.000";
var utcGivenDateTime = DateTime.Parse(giveDateTime);???
var localConvertedTime ???
Console.WriteLine("Given Date: ", giveDateTime);
Console.WriteLine("Given UTC DateTime ", utcGivenDateTime);
Console.WriteLine("Converted Local Time ", localConvertedTime);
Console.ReadLine();
}
}
要轉換為本地時間,您需要將其轉換為的時區:
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Brazilian Standard Time");
var localConvertedTime = TimeZoneInfo.ConvertTimeFromUtc(utcGivenDateTime, timeZoneInfo);
不幸的是,本地時區當前是特定於系統的。 如果您需要與系統無關,您可能需要查看第三方庫,如NodaTime 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.