C# 用户转换的日期时间?
我从一个字符串的使用中得到了一个时间。该时间假定为东部时间。我需要将其作为UTC时间存储在数据库中。我该怎么做 DateTime.SpecifyKind不接受东部。在另一篇文章中,我读了一些关于使用DateTimeOffset的内容C# 用户转换的日期时间?,c#,.net,datetime,C#,.net,Datetime,我从一个字符串的使用中得到了一个时间。该时间假定为东部时间。我需要将其作为UTC时间存储在数据库中。我该怎么做 DateTime.SpecifyKind不接受东部。在另一篇文章中,我读了一些关于使用DateTimeOffset的内容 DateTime dateNow=DateTime.Now; WriteLine(“日期和时间为{0}UTC。”, TimeZoneInfo.ConvertTimeToUtc(dateNow)); 来自: 相关问题:TimeZoneInfo是System.Core
DateTime dateNow=DateTime.Now;
WriteLine(“日期和时间为{0}UTC。”,
TimeZoneInfo.ConvertTimeToUtc(dateNow));
来自:
相关问题:TimeZoneInfo是System.Core.dll中的一个对象。 DateTime dateNow = DateTime.Now; Console.WriteLine("The date and time are {0} UTC.", TimeZoneInfo.ConvertTimeToUtc(dateNow));
DateTime easternTime = new DateTime(2007, 01, 02, 12, 16, 00);
string easternZoneId = "Eastern Standard Time";
try
{
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById(easternZoneId);
Console.WriteLine("The date and time are {0} UTC.",
TimeZoneInfo.ConvertTimeToUtc(easternTime, easternZone));
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine("Unable to find the {0} zone in the registry.",
easternZoneId);
}
catch (InvalidTimeZoneException)
{
Console.WriteLine("Registry data on the {0} zone has been corrupted.",
easternZoneId);
}