如何在 JavaScript 中像这样格式化日期和时间?
March 05, 2012 @ 14:30 (UTC - 9:30)
我使用这段代码来计算 EST 时间:
function getDate() {
var now = new Date();
var utc = now.getTime() + (now.getTimezoneOffset() * 60000);
return new Date(utc + (3600000 * -4));
}
最佳答案
我使用 Tats 推荐的日期时间格式,因为手动执行它是一个巨大的 PIA。
var yourDate = dateFormat(getDate(), "mmmm dd, yyyy @ HH:MM) + "(UTC -9:30)";
请记住,这不支持夏令时。您要求使用您的格式的 UTC -9:30,但您的函数转换为 -4。另外,我相信 now.getTime 以 UTC 返回。所以你可以在那里添加你的差异。
关于javascript - 格式化日期时间 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9709989/