简体   繁体   中英

Daylight saving in timestamps

I'm running a matlab function ( fastinsert ) to insert data into MySQL. The results are correct for the whole year except for 1 hour in March, during daylight saving. In fact it seems that I cannot insert data between 2:00am and 3:00am on that day.

For example with:

 ts =        2006           3          26           2          30           0

looking within the matlab function I found that the problem lies into:

 java.sql.Timestamp(ts(1)-1900,ts(2)-1,ts(3),ts(4),ts(5),secs,nanosecs)

that gives as a result:

 2006-03-26 03:30:00.0

How can I solve this?

I've run into similar problems in storing datetime on many occasions. Treating the value as a derived value seems to make the most sense. In other words, instead of storing the local time store the value as GMT and Time Zone . Then derive the appropriate value when you query the data.

This has the added benefit of making it possible to store values from multiple locations without having to worry about confusion down the road.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM