How can I convert time of day to UTC seconds in C#
Asked
Active
Viewed 5,544 times
2 Answers
2
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.

KMån
- 9,896
- 2
- 31
- 41
2
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.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194