I need the next flow:
var a = new Date(1337324400000, 'Europe/Amsterdam'); //+2h console.log(a); // for example 12:00 Mon ... a.setTimeZone('Europe/Kiev'); //+3h console.log(a); // 13:00 Mon ...
Is there such possibility in nodejs utils api ?
The zone offset can be Z for UTC or it can be a value "+" or "-" from UTC. For example, the value 08:00-08:00 represents 8:00 AM in a time zone 8 hours behind UTC, which is the equivalent of 16:00Z (8:00 plus eight hours). The value 08:00+08:00 represents the opposite increment, or midnight (08:00 minus eight hours).
The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, local timezone is behind the UTC and if it is negative, the local timezone if ahead of UTC.
thejh is right, you cannot change the timezone. Use a JS time library (like moment. js) and add / subtract hours instead. The easiest and the correct way to do this is to simply change your system's time zone.
To get a UTC Date object in Node. js and JavaScript, we can call the date's toUTCString method. to create a new Date instance and call toUTCString to return the UTC date string version of the current date time.
You can use node-time, as follows:
var time = require('time'); var a = new time.Date(1337324400000); a.setTimezone('Europe/Amsterdam'); console.log(a.toString()); // Fri May 18 2012 09:00:00 GMT+0200 (CEST) a.setTimezone('Europe/Kiev'); console.log(a.toString()); // Fri May 18 2012 10:00:00 GMT+0300 (EEST)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With