2 回答
TA贡献1848条经验 获得超2个赞
使用moment-timezone对日期和时区进行高级操作。
解决方案:
let date = "07-Oct-2019 11:02"
console.log(
moment.tz(date, "DD-MMM-YYYY HH:mm", "Europe/London").utc().format("DD-MMM-YYYY HH:mm")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone-with-data.min.js"></script>
TA贡献1851条经验 获得超4个赞
var date = "07-Oct-2019 11:02";
var a = date.split("-");
var b = a[2].split(" ");
var dateFormat = a[0] + ' - ' + a[1] + ' - ' + b[0] + ' ' + b[1];
var convertedDate = new Date(dateFormat);
weekdayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dateString = convertedDate.getDate() + "-" + monthNames[convertedDate.getMonth()] + "-" + convertedDate.getFullYear() +" "+ convertedDate.getHours() + ":" + ("00" + convertedDate.getMinutes()).slice(-2);
console.log(dateString);
添加回答
举报