开发者

UTC and Universal Time

In C#, what is the difference between UTC and Universal Time开发者_JS百科? What are the functions available?


I would think they're both the same - according to Wikipedia, UTC is Coordinated *Universal* Time.

.NET supports UTC through a number of function on the DateTime struct. E.g. there is are functions like DateTime.ToUniversalTime (and DateTime.ToLocalTime to convert back, of course) or DateTime.UtcNow available.


No difference. DateTime.UtcNow gives you the current time in UTC. The Timezone class has functions to convert to and from UTC date/time to date/time in any timezone.


UTC = Universal Time.

You can convert your current local time to UTC by

DateTime dt= DateTime.UtcNow;

or convert a specified date/time by

TimeZoneInfo myTZInfo = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");

// DateTime.SpecifyKind(Convert.ToDateTime("04:35 AM"), DateTimeKind.Unspecified), myTZInfo) tells whether you are conetring a local time or UTC, you can always leave it as unspecified

TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(Convert.ToDateTime("2015-01-06 14:00:00.000"), DateTimeKind.Unspecified), myTZInfo).ToString("hh:mm tt")

you can get all time zone ids by==>

ReadOnlyCollection<TimeZoneInfo>  tzc= TimeZoneInfo.GetSystemTimeZones();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜