How to convert current system time to UTC seconds

How can I convert the time of day to UTC seconds in C #

+3
source share
2 answers

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

See Converting time between time zones ;

+2
source

Your question is not entirely clear, but you can after:

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

For example, it is currently around 7:15 BST (Europe / London), which is 6:15 UTC. The above code gives 22573.6674426, which is slightly larger (6 * 60 + 15) * 60.

+2
source

Source: https://habr.com/ru/post/1739426/


All Articles