Вопрос

I know that JavaScript doesn't NULL terminate strings like C or C++ do, but I ran into a case which I can't explain.

Look at the following code (executed in Node.js v0.10.5) :

> new Date('123')

Fri Jan 01 123 00:00:00 GMT+0100 (CET) // UNIX epoch : -58285702800000

> new Date('123\056')

Fri Jan 01 123 00:00:00 GMT+0100 (CET) // UNIX epoch : -58285702800000

> new Date('123\0456')

Tue Jun 01 123 00:00:00 GMT+0200 (CEST) // UNIX epoch : -58272660000000

> new Date('123\0567')

Thu Jul 01 123 00:00:00 GMT+0200 (CEST) // UNIX epoch : -58270068000000

> new Date('123\0999')

Fri Jan 01 123 00:00:00 GMT+0100 (CET)  // UNIX epoch : -58285702800000

> new Date('123\0555')

Sat May 01 123 00:00:00 GMT+0200 (CEST) // UNIX epoch : -58275338400000

> new Date('123\0655')

Sat Jan 01 12355 00:00:00 GMT+0100 (CET) // UNIX epoch : 327718911600000

I'm not sure what's happening here, can someone explain it to me ?

It would seem that sometimes, the integers after a NULL byte define the month of the date, but the month not always correspond to the following number.

Это было полезно?

Решение

Those are 3-digit octal escapes, not null bytes. So for example '123\0456' is realy '123%6'.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top