How to format BC dates (for example, "-700-01-01")?

How to format ISO BC dates with Moment.js?

moment("-700-01-01").year(); // 700 (WRONG) moment("-0700-01-01").year(); // 700 (WRONG) moment("-000700-01-01").year(); // -700 (RIGHT) 

For some reason, the year notation works with 6 digits. Is this the "right" way? Why are there no such signs as "-700-01-01" ?

+5
source share
2 answers

This is not a problem with Moment.js; the same thing happens if you try to initialize a Date() object with the string you use. If you first create it as a Date() object and manually assign the year using setYear() , it takes a date of -700 :

 var date = new Date(); date.setYear(-700); moment(date).year(); 
 > -700 

However, as Niels Kerentjes pointed out , calculating dates that are far back become quite complicated and may not be entirely reliable.

If you want "-700-01-01", you can set the year, month and day separately:

 date.setYear(-700); date.setMonth(0); date.setDate(1); console.log(date); 
 > Fri Jan 01 -700 11:53:57 GMT+0000 (GMT Standard Time) 

As for whether the first day of the 1st month at 700BC was actually Friday ... you have to see what you yourself.

+3
source

in your example, the minus sign is also used as a separator between years, months, and days. As you note in a comment on James's answer, using a coma as a separator helps to distinguish.

0
source

Source: https://habr.com/ru/post/1202585/


All Articles