在javascript日期需要时区帮助

时间:2011-08-05 15:13:55

标签: javascript

感谢那些向我展示建立客户约会的人......我建造了它...现在我只需要时区:

    var months = new Array(13);
           months[0]  = "Jan";
           months[1]  = "Feb";
           months[2]  = "Mar";
           months[3]  = "Apr";
           months[4]  = "May";
           months[5]  = "Jun";
           months[6]  = "Jul";
           months[7]  = "Aug";
           months[8]  = "Sep";
           months[9]  = "Oct";
           months[10] = "Nov";
           months[11] = "Dec";


        var now = new Date();
        var hour        = now.getHours();
        var minute      = now.getMinutes();
        var second      = now.getSeconds();
        var monthnumber = now.getMonth();
        var monthname   = months[monthnumber];
        var monthday    = now.getDate();
        var year        = now.getYear();



        var systemdate = monthday + " " + monthname + " " + year + " " + "@ " + hour  + ":" + minute + ":" + second

这给了我:  2011年8月5日@ 11:11:14

我需要: 2011年8月5日美国东部时间晚上11:11:14

感谢

2 个答案:

答案 0 :(得分:3)

尝试使用以下代码获取缩写时区:

var timeZoneAbbr = new Date().toString().replace(/^.*\(|\)$/g, "").replace(/[^A-Z]/g, "");

我在代码here中找到了替换表达式。另外,Here's是一个小小的测试对象。<​​/ p>

答案 1 :(得分:2)

var gmt = -now.getTimezoneOffset()/60;

这会给你几小时的偏移。然后,您可以使用

创建一系列GMT字符串