Node: Inconsistent timestamp between v6.0.0 and older versions

Created on 27 Apr 2016  路  5Comments  路  Source: nodejs/node

  • Version: Node.js v6.0.0, npm v3.8.6
  • Platforms: Linux Mint 17.3, Ubuntu 16.04, Alpine 3.3.3

I get an issue while calculating time from a date string. Here is the function strtotime, as its name, would convert a standard date string to Unix timestamp.

 var strtotime = (t) => {
    return new Date(t).getTime();
 };

From my local time (GMT+7), the result for this function is different between node.js v6.0.0 and older versions.

let s = 'Thu, 18 Feb 2016 15:28:20 GMT+07';
let t = strtotime(s); 

t is equal to 1455784100000 in node.js v6.0.0 but 1455808880000 in older versions.

Issue also happens in Travis server. Here is the build info:

https://travis-ci.org/ndaidong/bella.js/builds/126068193

Anyone get the same problem? And what wrong here?

Thanks,
Dong

V8 Engine question

Most helpful comment

Cool, closing this then. :)

All 5 comments

This seems more like a bug that鈥檚 fixed in v6 than one that鈥檚 introduced. Thu, 18 Feb 2016 15:28:20 GMT+07 corresponds to the unix timestamp 1455784100(000).

@addaleax : did you mean that the result calculated by older versions was incorrect?

@ndaidong I think so, yes. For Node.js 5.11.0:

> new Date('Thu, 18 Feb 2016 15:28:20 GMT+07').toString()
'Thu Feb 18 2016 15:21:20 GMT+0000 (UTC)'

I think what when wrong is that GMT+07 got parsed as GMT+0007, not GMT+0700, i.e. 7 minutes after GMT, not 7 hours.

@addaleax you're rock! It seems that is exactly the original cause of issue. Thank you.

Cool, closing this then. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danialkhansari picture danialkhansari  路  3Comments

srl295 picture srl295  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments