Javascript DateFormat for different timezones

后端 未结 9 2088
小蘑菇
小蘑菇 2020-12-16 16:42

I\'m a Java developer and I\'m used to the SimpleDateFormat class that allows me to format any date to any format by settings a timezone.

Date date = new Dat         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 17:06

    Don't write your own stuff; just get datejs: http://www.datejs.com/

    You can figure out what the timezone offset is set to in the execution environment like this:

    var local = new Date();
    var utc = Date.UTC(local.getFullYear(), local.getMonth(), local.getDate(), local.getHours(), local.getMinutes(), local.getSeconds(), local.getMilliseconds());
    var tz = (utc - local.getTime()) / (60 * 60 * 1000);
    

提交回复
热议问题