开发者

How do I convert current system time in to UTC seconds

开发者 https://www.devze.com 2022-12-25 13:35 出处:网络
How c开发者_高级运维an I convert time of day to UTC seconds in C#Not sure if I understand correctly, you want to get the second of UTC? Try: int nSeconds = DateTime.SpecifyKind(DateTime.Now, DateTimeK

How c开发者_高级运维an I convert time of day to UTC seconds in C#


Not sure if I understand correctly, you want to get the second of UTC? Try: int nSeconds = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Local).ToUniversalTime().Second; to get the seconds.

See Converting Times Between Time Zones;


Your question isn't entirely clear, but you might be after:

TimeSpan timeOfUtcDay = DateTime.UtcNow.TimeOfDay;
double seconds = timeOfUtcDay.TotalSeconds;

For example, it's currently about 7:15 BST (Europe/London), which is 6:15 UTC. The above code gives 22573.6674426, which is just a bit more than (6 * 60 + 15) * 60.

0

精彩评论

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

关注公众号