Unix time stamp conversion is different in Mysql and Oracle

前端 未结 1 1113
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 11:24

Unix time stamp conversion giving tow different result in mysql and oracle

select FROM_UNIXTIME(1387444958) from dual;

Output :2013-12-19 1

相关标签:
1条回答
  • 2021-01-16 11:50

    Unix timestamp is seconds from 1970-01-01 00:00:00 UTC which is actually 1970-01-01 01:00:00 in your local timezone (or the timezone where your MySQL server is located). Looks like FROM_UNIXTIME takes this into account.

    For Oracle you can use this function:

    FUNCTION UnixTime2Timestamp(UnixTime IN NUMBER) RETURN TIMESTAMP IS
    BEGIN
        RETURN (TIMESTAMP '1970-01-01 00:00:00 UTC' + UnixTime * INTERVAL '1' SECOND) AT LOCAL;
    END UnixTime2Timestamp;
    

    I assume if you like to get UTC time in MySQL then you have to run

    select 
       CONVERT_TZ(FROM_UNIXTIME(1387444958),'{your local timezone}','UTC') 
    from dual;
    
    0 讨论(0)
提交回复
热议问题