在JavaScript中设置UTC -5偏移量

时间:2019-04-07 20:50:12

标签: javascript wordpress utc

谁知道我将如何修改以下内容以反映UTC偏移量-5?这是整个功能,因此可能超出实际需要修改的范围。谢谢

    function makeUtcWrapper(d) {

    function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) {
        sourceObj[sourceMethod] = function() {
            return targetObj[targetMethod].apply(targetObj, arguments);
        };
    };

    var utc = {
        date: d
    };

    // support strftime, if found

    if (d.strftime != undefined) {
        addProxyMethod(utc, "strftime", d, "strftime");
    }

    addProxyMethod(utc, "getTime", d, "getTime");
    addProxyMethod(utc, "setTime", d, "setTime");

    var props = ["Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds"];

    for (var p = 0; p < props.length; p++) {
        addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]);
        addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]);
    }

    return utc;
};

1 个答案:

答案 0 :(得分:0)

如果d应该是Date对象,则可以执行以下操作:

MyHelloDelegate Hello = delegate { Console.WriteLine("Hello from delegate "); };

但是请注意,这是重复的:How to get UTC offset in javascript (analog of TimeZoneInfo.GetUtcOffset in C#)