Stories
Slash Boxes
Comments

SoylentNews is people

Log In

Log In

Create Account  |  Retrieve Password


stderr (11)

stderr
(email not shown publicly)

Journal of stderr (11)

The Fine Print: The following are owned by whoever posted them. We are not responsible for them in any way.
Sunday March 30, 14
12:42 AM
Code
Just testing some DST stuff... Entry posted Sunday March 30 2014 at 01:42:00 CET. 18 minutes before DST starts in Europe.
Tuesday February 18, 14
08:44 PM
Code

For some time I have been working on a JavaScript library for working with timezones. The name is tzdata-javascript

To use it, you would first load the library like this:

<script type="text/javascript" src="http://tzdata-javascript.org/tzdata-javascript.js">
</script>

(SoylentNews seems to break the URL for the .js file in a weird place, but I'm sure you can figure out what it should be...)

And then use it like this:

<script type="text/javascript">
    # Load the timezone you want to use:
    var la=new tzdata_javascript.zoneinfo("America/Los_Angeles");
    var cph=new tzdata_javascript.zoneinfo("Europe/Copenhagen");
    var hk=new tzdata_javascript.zoneinfo("Asia/Hong_Kong");

    # Find the timestamp (in ms since Epoch) you want to convert to localtime:
    var now=new Date().valueOf();

    # Call the strftime() function of each of the timezones, you loaded earlier:
    alert(
        "The time in Los Angeles is : "+la.strftime("%+",now)+"\n"+

        "The time in Copenhagen is : "+cph.strftime("%+",now)+"\n"+

        "The time in Hong Kong is : "+hk.strftime("%+",now)+"\n"
    );
</script>

And that's about it... :-)

The librarys website has some more demos and examples.

08:18 PM