简体   繁体   中英

convert_tz change timestamp in 1 hour

I have used convert_tz to insert local date and time into MYSQL table. But there is an issue and it will change time in 1 hour. I don't know when it changing and why.

Example:

Priviesly used - CONVERT_TZ(NOW(), 'UTC', '+10:30') to get local time 10:00AM

Now used - CONVERT_TZ(NOW(), 'UTC', '+9:30') to get local time 10:00AM

When I create website I used CONVERT_TZ(NOW(), 'UTC', '+10:30') to get local date and time. But from today I need to change all CONVERT_TZ(NOW(), 'UTC', '+10:30') to CONVERT_TZ(NOW(), 'UTC', '+9:30') to get correct local date and time. Otherwise time is 1 hour added.

How to solve this issue?

UPDATE: I am using inmotion hosting.

UPDATE 2:

I am using to get date and time following code in PHP.

$lastdatepost = new DateTime("now", new DateTimeZone('Asia/Colombo'));
$lastdatepost = $lastdatepost->format('Y-m-d H:i:s');

This will effect with above CONVERT_TZ(NOW(), 'UTC', '+10:30') SQL code and both date and time different which is 1 hour added. Then give error.

UTC offsets change over the course of the year in most places around the globe due to Daylight Saving Time aka Summer Time. India isn't one of those places, but the US went on DST today, so the timing is suspicious.

What is your application? If PHP and MySQL have different ideas of what time it is, that implies to me that one of them must be storing local time and have an incorrect offset to UTC. Does your application perhaps run on Windows?

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