我正在使用一个适用于多个时区的应用程序.
这里服务器返回的纪元日期.
我需要一个可以将Epoch Date转换为JavaScript Date的函数.
此外,我还要求将JavaScript日期发送到Epoch Date,以便在服务器上发回帖子数据.
@Parth Trivedi我为你做了两个功能.
$(document).ready(function () {
alert("Date to Epoch:" + Epoch(new Date()));
alert("Epoch to Date:" + EpochToDate(Epoch(new Date())));
});
//Epoch
function Epoch(date) {
return Math.round(new Date(date).getTime() / 1000.0);
}
//Epoch To Date
function EpochToDate(epoch) {
if (epoch < 10000000000)
epoch *= 1000; // convert to milliseconds (Epoch is usually expressed in seconds, but Javascript uses Milliseconds)
var epoch = epoch + (new Date().getTimezoneOffset() * -1); //for timeZone
return new Date(epoch);
}