繁体   English   中英

需要有关JavaScript日期的时区的帮助

[英]Need help with time zone on javascript date

感谢向我展示了建立自定义日期的属性的人...我建立了它...现在我只需要最后的时区:

    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

谢谢

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

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

我在这里的代码中找到了replace表达式。 另外, 这是一个测试的小提琴。

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

这将为您提供小时数的补偿。 然后,您可以像几个月一样制作GMT字符串数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM