Convert UTC Epoch to local date

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

    @Amjad, good idea, but a better implementation would be:

    Date.prototype.setUTCTime = function(UTCTimestamp) {
        var UTCDate = new Date(UTCTimestamp);
        this.setUTCFullYear(UTCDate.getFullYear(), UTCDate.getMonth(), UTCDate.getDate());
        this.setUTCHours(UTCDate.getHours(), UTCDate.getMinutes(), UTCDate.getSeconds(), UTCDate.getMilliseconds());
        return this.getTime();
    }
    

提交回复
热议问题