0

So I have the following Time as a strong:

0:00:00.000

and I use the following strptime:

Time.strptime(times[0], "%H:%M:%S.%L")

Expected Result 0:00:00.000

Actual Result 6:00:00.000

I am 6 hours behind UTC outside of daylight savings. So that might explain why it s saving six hours ahead. I've tried to wrap it in a Time.use_zone and set the zone to UTC but that still doesn't do the trick.

For now I have it subtracting six hours before saving the record. But I'd like to figure out how to force it to save the timing to the correct hour.

Patrick Vellia
  • 399
  • 2
  • 9
  • I wonder if the following question/answers are helpful to you: https://stackoverflow.com/questions/7909128/strptime-with-timezone – Igor Drozdov Jun 23 '22 at 08:07
  • my understanding to set to UTC is using this command Time.zone = 'UTC', have you tried with this – widjajayd Jun 23 '22 at 08:07

1 Answers1

0

Try with Time.zone

t = "0:00:00.000"
Time.zone.strptime(t, "%H:%M:%S.%L")

=> Thu, 23 Jun 2022 00:00:00.000000000 CDT -05:00
Thomas Van Holder
  • 1,137
  • 9
  • 12
  • Without changing the Zone, doing this Time.zone.strptime("0:00:00.000", "%H:%M:%S.%L") saved it correctly as UTC at 0 hours. Thank you – Patrick Vellia Jun 23 '22 at 10:41