How to get a timestamp older than 1901

I am trying to find to accurately count the number of seconds from January 1, 1850 to the present in several languages ​​(JavaScript, C ++ and Python [don’t even ask, I haven’t asked these questions for a long time]).

The problem is that the storage timestamps are stored as signed 32-bit integers, so I cannot get the timestamp for dates older than 1901 to easily subtract the current timestamp, etc. So how do I do what I want to do?

+3
source share
5 answers

There is a datetime module in python . In particular, a date class will help.

from datetime import date
print date(1850, 1, 1).weekday()  # 1, which is Tuesday 
# (Mon is 0)

Edit

, , timedelta .

from datetime import datetime
td = datetime.now() - datetime(1850, 1, 1)
print (86400*td.days)+td.seconds  # seconds since then till now
+4

, - :

1. 01/01/1850 00:00 01/01/1901 00:00. - ( M)

2. 01/01/1901 00:00 .

3. 2 + M. , .

+3

WIN32 SystemTimeToFileTime.

FILETIME - 64- , 100- 1 1601 (UTC).

FILETIME. ULARGE_INTEGER (t.dwLowDateTime + t.dwHighDateTime < 32) .

+1

, , .

function secondsSince(D){
 D= new Date(Date.parse(D));
 D.setUTCHours(0,0,0,0); 
 return Math.floor((new Date()-D)/1000);
}

//

var daystring = '1 1850 , ss = secondsSince (daystring), diff = ss/(60 * 60 * 24 * 365,25);

alert (' ' + ss + ' 00:00:00 (GMT) ' + daystring + '\n\n ' + diff.toFixed(2) + 'years.');

0

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


All Articles