3

我在 GitHub 上看到了这个项目,它将给定的时区转换为另一个时区。我在如何使这项工作上遇到困难。我下载了文件并将其解压缩,然后创建了一个 html 文件,如下所示:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
        <title>Time Zone Converter</title>
        <script src="timezone-js-master/src/date.js" type="text/javascript"></script>
        <script type="text/jscript" language="jscript">
            function init() {
                var dt = new timezoneJS.Date("2012/04/10 10:10:30 +0000", 'Europe/London');
                dt.setTimezone("Asia/Jakarta");

                alert(dt);
            }
        </script>
    </head>
    <body onload="init()">

    </body>
</html>

我希望会弹出一些消息,但上面的 html 实际上不起作用。显然我错过了一些东西。

你能帮忙吗?

4

1 回答 1

0

As mentioned in some of the github comments, the constructor is not really clear.

There is also the added complexity of re-setting the perspective when passing your timezoneJS instance in a new Date() instance.

To get time date/time in another timezone you must instantiate, set the timezone using an Olson string, then get the converted value out of the timezoneJS instance.

So the following code:

var dt = new window.timezoneJS.Date(new Date());
console.debug(dt.toString());
dt.setTimezone('America/Los_Angeles');
console.debug(dt.toString());

Yields:

2013-07-18 19:09:30 //now
2013-07-18 16:09:30 //now... in LA
于 2013-07-18T23:12:19.537 回答