Convert UTC Epoch to local date

后端 未结 16 1502
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 10:10

I have been fighting with this for a bit now. I’m trying to convert epoch to a date object. The epoch is sent to me in UTC. Whenever you pass new Date() an epoc

16条回答
  •  隐瞒了意图╮
    2020-11-22 10:49

    To convert the current epoch time in [ms] to a 24-hour time. You might need to specify the option to disable 12-hour format.

    $ node.exe -e "var date = new Date(Date.now()); console.log(date.toLocaleString('en-GB', { hour12:false } ));"
    
    2/7/2018, 19:35:24
    

    or as JS:

    var date = new Date(Date.now()); 
    console.log(date.toLocaleString('en-GB', { hour12:false } ));
    // 2/7/2018, 19:35:24
    
    console.log(date.toLocaleString('en-GB', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false } ));
    // 19:35:24
    

    Note: The use of en-GB here, is just a (random) choice of a place using the 24 hour format, it is not your timezone!

提交回复
热议问题