The best property to store the current datetime in database

This question already has an answer here:

  • Daylight saving time and time zone best practices [closed] 30 answers

  • It's rarely needed to store datetime info using locale other than the server. Most of the time, a datetime event is calculated by the server, so unless you are storing a user provided value (birth date, for example) you ought to have it stored as UTC.

    And, even with most user-provided datetime values (scheduling an appointment, for example) you have to normalize that value to UTC before storing it in the database. That way dates will remain consistent even if the user timezone changes (during a trip, for example, or when daylight saving are effective.)


    Storing it as a DATETIME data type is the best datatype to use. But you should store the date as UTC date and then convert it to the timezone you need.

    That way the times are consistent across timezones. Otherwise you can store them in the full time including timezone in the database. For example, in MS Sql Server you can use datetimeoffset.

    链接地址: http://www.djcxy.com/p/29346.html

    上一篇: 在Java ee应用程序中使用日期时间

    下一篇: 将当前日期时间存储在数据库中的最佳属性