格式化日期时间JavaScript [英] Format date time JavaScript

查看:151
本文介绍了格式化日期时间JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JavaScript中格式化这样的日期和时间?

How to format date and time like this in JavaScript ?


2012年3月5日@ 14:30(UTC - 9:30)

March 05, 2012 @ 14:30 (UTC - 9:30)

我使用此代码计算EST时间:

I use this code to calculate EST time :

function getDate() {
    var now = new Date();
  var  utc = now.getTime() + (now.getTimezoneOffset() * 60000);

    return new Date(utc + (3600000 * -4));
}


推荐答案

我使用日期时间 - Tats建议的格式化,因为手动操作是一个巨大的PIA。

I use the date-time-format that Tats recommended because doing it manually is a huge PIA.

var yourDate = dateFormat(getDate(), "mmmm dd, yyyy @ HH:MM) + "(UTC -9:30)";

请记住这不是夏令时意识到..你要求格式的UTC -9:30,但你的功能转换为-4。另外,我相信now.getTime以UTC格式返回..所以你可以添加你的不一样。

Keep in mind this isn't Daylight Savings aware.. and you are asking for UTC -9:30 in your format, but your function converts to -4. Also, I believe that now.getTime returns in UTC.. so you can just add your difference there.

JavaScript日期格式

这篇关于格式化日期时间JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆