【问题标题】:how to get timestamp value with timezone abbreviation如何使用时区缩写获取时间戳值
【发布时间】:2017-02-16 21:09:53
【问题描述】:

是否可以将时区缩写与时间戳值一起附加/包含?下面的代码返回类似这样的值,例如:2-16-2017 @ 16:7:20

我想在这个值中包含时区缩写吗?有什么想法

var currentdate = new Date(); 
var datetime =  (currentdate.getMonth()+1) + "-"
                + currentdate.getDate()  + "-" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();alert(datetime)

谢谢, 穆图

【问题讨论】:

    标签: javascript timestamp


    【解决方案1】:

    我不知道你是否可以得到时区缩写,但绝对可以得到偏移量。

    var offset = new Date().getTimezoneOffset();
    console.log(offset);
    

    【讨论】:

      【解决方案2】:

      另一种选择是使用toTimeString(),而不是手动连接时间部分:

      currentdate.toTimeString() //"01:19:10 GMT+0400 (SAMT)"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-06
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        • 1970-01-01
        • 2013-10-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多