Forum Discussion
Why is UTC datetime being converted to local datetime?
- 3 years ago
The weird thing to me is that your seconds digits are different. I would expect them to match exactly. Maybe a caching thing? Does Refresh Preview make them match?
The reason the number for local time and UTC should match is that they both represent the same thing, just in a different format. If you remove the time zone from UTC, then they'll be different.
DateTimeZone.RemoveZone(DateTimeZone.UtcNow())To get the offset of your local time, you can use
DateTimeZone.ZoneHours(DateTimeZone.LocalNow())If your local time zone also has a minutes offset, then you'll want to use DateTimeZone.ZoneMinutes or, alternatively, DateTimeZone.ToRecord to get all the components.
The weird thing to me is that your seconds digits are different. I would expect them to match exactly. Maybe a caching thing? Does Refresh Preview make them match?
The reason the number for local time and UTC should match is that they both represent the same thing, just in a different format. If you remove the time zone from UTC, then they'll be different.
DateTimeZone.RemoveZone(DateTimeZone.UtcNow())
To get the offset of your local time, you can use
DateTimeZone.ZoneHours(DateTimeZone.LocalNow())
If your local time zone also has a minutes offset, then you'll want to use DateTimeZone.ZoneMinutes or, alternatively, DateTimeZone.ToRecord to get all the components.