Edit: database is MS SQL Server 2014 and above
I need to store datetimes in a database table in UTC time. The table field itself is a
datetime type, so by itself it doesn’t have an attached timezone offset, however I need to convert my local timezone time to the equivalent UTC time, and have that stored, as otherwise daylight savings will destroy my data.
I’m creating dates using
system.date.* functions. From what I understand, the
java.util.Date object returned by these really just hold the number of millis since the epoch, which is in UTC by definition. When I use these Dates with the runPrepUpdate function however, the SQL database is storing the local datetime.
How can I store in UTC? (I’ve already tried to get the local timezone offset hours so I can subtract it from the local time e.g. +10:30 => 10.5 before passing it to the runPrepUpdate function, but it’s been far more difficult than I thought it would be… I haven’t tried to extract the values out of the text string itself yet, but that would be horrible and a very ast resort!)