2

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

Tauqeer
  • 21
  • 1
  • 2
  • possible duplicate of [Convert UTC/GMT time to local time](http://stackoverflow.com/questions/179940/convert-utc-gmt-time-to-local-time) – devnull Mar 16 '14 at 13:47

2 Answers2

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.

See Converting Times Between Time Zones;

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