简而言之,DateTimeOffset是一种瞬时时间(即绝对时间),DateTime是一种历法时间(即钟表时间)。 最后,这两个数据类型都有Now和UtcNow两个方法。Now用于获取现在的时间,UtcNow获取Utc的现在时间。而实际上,Now内部是先调用UtcNow,然后进行转换得到。所以,在一般情况下,都应该使用UtcNow。 获取时间戳new DateTimeOffset(Dat...
简而言之,DateTimeOffset是一种瞬时时间(即绝对时间),DateTime是一种历法时间(即钟表时间)。 最后,这两个数据类型都有Now和UtcNow两个方法。Now用于获取现在的时间,UtcNow获取Utc的现在时间。而实际上,Now内部是先调用UtcNow,然后进行转换得到。所以,在一般情况下,都应该使用UtcNow。 在文章结束的时候,给大家留个小...
public static DateTimeOffset UtcNow { get; } 屬性值 DateTimeOffset 其日期和時間為目前 Coordinated Universal Time (UTC),且其位移為 Zero 的物件。 範例 下列範例說明國際標準時間 (UTC) 與當地時間之間的關聯性。 C# 複製 DateTimeOffset localTime = DateTimeOffset.Now; DateTimeOffset utcTime = DateTimeOff...
DateTime.UtcNowandDateTimeOffset.UtcNoware 2.5x slower compared to 2.2 [Benchmark]publicDateTimeOffsetGetUtcNow()=>DateTimeOffset.UtcNow;[Benchmark]publicDateTimeGetUtcNow()=>DateTime.UtcNow; Repro git clone https://github.com/dotnet/performance.gitcdperformance #ifyou don't have cli installed and...
DateTimeOffset localTime = DateTimeOffset.Now; DateTimeOffset utcTime = DateTimeOffset.UtcNow; Console.WriteLine("Local Time: {0}", localTime.ToString("T")); Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString()); Console.WriteLine("UTC: {0}", utcTime.ToString("T"));...
{2}", date1, date2, difference);// Find difference between Now and UtcNow using DateTimeOffsetdateOffset1 = DateTimeOffset.Now; dateOffset2 = DateTimeOffset.UtcNow; difference = dateOffset1 - dateOffset2; Console.WriteLine("{0} - {1} = {2}", dateOffset1, dateOffset2, difference);//...
{2}", date1, date2, difference);// Find difference between Now and UtcNow using DateTimeOffsetdateOffset1 = DateTimeOffset.Now; dateOffset2 = DateTimeOffset.UtcNow; difference = dateOffset1 - dateOffset2; Console.WriteLine("{0} - {1} = {2}", dateOffset1, dateOffset2, difference);//...
DateTimeOffset thisDate;// Show output for UTC timethisDate = DateTimeOffset.UtcNow; Console.WriteLine(thisDate.ToString());// Displays 3/28/2007 7:13:50 PM +00:00// Show output for local timethisDate = DateTimeOffset.Now; Console.WriteLine(thisDate.ToString());// Displays 3/28/2007 12...
DateTimeOffset thisDate; // Show output for UTC time thisDate = DateTimeOffset.UtcNow; Console.WriteLine(thisDate.ToString()); // Displays 3/28/2007 7:13:50 PM +00:00 // Show output for local time thisDate = DateTimeOffset.Now; Console.WriteLine(thisDate.ToString()); // Displays 3/28...
DateTimeOffset localTime = DateTimeOffset.Now; DateTimeOffset utcTime = DateTimeOffset.UtcNow; outputBlock.Text += String.Format("Local Time: {0}", localTime.ToString("T")) + "\n"; outputBlock.Text += String.Format("Difference from UTC: {0}", localTime.Offset.ToString()) + "\n"...