开发者

Need help with time zone on javascript date

thanks to guys that showed me the prperties to build a 开发者_C百科custome date...I built it...now i just need the timezone at the end:

    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

This gives me: 5 Aug 2011 @ 11:11:14

I need: 5 Aug 2011 @ 11:11:14 EDT

THANKS


Try the following code to get the abbreviated timezone:

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

I found the replace expression in the code here. Also, Here's a fiddle for testing.


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

This will give you an offset in hours. Then you can make an array of GMT strings like you did it with months

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜