Convert UTC Epoch to local date

后端 未结 16 1537
佛祖请我去吃肉
佛祖请我去吃肉 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 11:13

    Considering, you have epoch_time available,

    // for eg. epoch_time = 1487086694.213
    var date = new Date(epoch_time * 1000); // multiply by 1000 for milliseconds
    var date_string = date.toLocaleString('en-GB');  // 24 hour format
    

提交回复
热议问题