Home > database >  MySQL time zone problem, use the datetime as the time of placing your order
MySQL time zone problem, use the datetime as the time of placing your order

Time:10-09

Deployed on the primary server multiple e-commerce sites of the country, according to different time zone and the web store order time fields, MySQL basically is to use a datetime types, N from the server, it is mainly used for backup and Read, and then type because MySQL storage time is no time zones,, following the time zone of the server system leads to if the master-slave server time zone is different, so synchronous data immediately past mistakes, risk is great, and some application has specified the east eight area or west five area (New York time), then the program is generated in the datetime format of time and then inserted into the database...

About the database time zone, it is actually on the server time zone in the system, how to design more reasonable science?

One way, all of the server system all use UTC time zones, mysql database table field can use datetime to storage time, JAVA applications such as PHP generate time in writing time zones are generated under the influence of the UTC time zones, is equal to the entire unification, so you must ensure that all the server time zone are unified in the UTC, query displayed to the user when converted into local user localtime, but there is a problem, such as in London, the local time is at eight o 'clock in the morning post, but if you really to convert the time, to the user in Beijing to see the release time is 5 PM, this show is unreasonable?

Scheme 2,
Server time zone Settings, any mysql storage time of the field in all use int timestamp, when written to all write Unix timestamp, but many have molding process is not the case, if such a well all changes, a large quantities, and the need to transform the old data, the second is also the problem above,

How to solve the problem of data time zone?

CodePudding user response:

MYSQL connection string in the WEB application and timezone setting,

CodePudding user response:

reference 1st floor ACMAIN_CHM response:
MYSQL connection string in the WEB application and timezone Settings,


If it is a new program, should be unified with the UTC and local time zone is better

CodePudding user response:

Posts in London 8 bit why 17 bit is to see in Beijing? Have a screenshot?

CodePudding user response:

reference solarsilvia reply: 3/f
8 bit posts in London why 17 bit is to see in Beijing? Have a screenshot?

Because the store is a timestamp, London at 8 o 'clock the timestamp, in Beijing time is 17 points,

CodePudding user response:

I think a timestamp and time zones, to a piece of storage, display, through the timestamp and the post the timezone in recovery time,
  • Related