Convert a Unix timestamp to time in JavaScript

前端 未结 29 2174
渐次进展
渐次进展 2020-11-21 04:57

I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it?

For example, in HH/MM/

29条回答
  •  情深已故
    2020-11-21 05:40

    See Date/Epoch Converter.

    You need to ParseInt, otherwise it wouldn't work:


    if (!window.a)
        window.a = new Date();
    
    var mEpoch = parseInt(UNIX_timestamp);
    
    if (mEpoch < 10000000000)
        mEpoch *= 1000;
    
    ------
    a.setTime(mEpoch);
    var year = a.getFullYear();
    ...
    return time;
    

提交回复
热议问题