In my database, I'm storing time as a BIGINT UTC value.
In my test data SQL dump I'd like to see the time in UTC for readability. However, the MySQL unix_timestamp function expects time in the local time zone,开发者_如何学JAVA which I'm trying to avoid.
I've looked around and the only way I've found of converting the UTC time string to a unix time stamp is using this expression:
SELECT unix_timestamp(CONVERT_TZ('2011-08-08 06:00:00','UTC',@@global.time_zone))
Is there a better way to do this?
If you stored it as a timestamp instead of a bigint it would happen automatically just by setting the timezone.
Also, I don't really understand what you are doing. You are storing unixtime as your bigint column correct? So I don't get why you are using the unix_timestamp()
function - that converts TO a unixtime, not from it.
I guess this is what you need:
SET time_zone = '+0:00';
SELECT FROM_UNIXTIME(col) FROM table;
精彩评论