让我们做一些数学
You can use 7 alphanumeric digits. Each alphanumeric digit take a value from 36 possible different values (26 letters, 10 decimal digits)
So we have 36^7 different values, that is 78364164096.
Now we compute the number of different values needed to represent a given timestamp in one year.
To simplify things a bit we will allow some values that will never happen (ex: 31th november).
因此,我们已经
month: 12 -> coded from 0 to 11
day: 31 -> coded from 0 to 30
hour: 24
minute: 60
second: 60
which gives use 32140800 different possibilites
We now divide 78364164096 / 32140800 which is ~2438, thus we will give an enumeration of timestamps from 00:00 jan 1 0000 to 23:59 dec 31 2437
当时编码正在编码。
X = second + minute*60 + hour*60*60 +
day*60*60*24 + month*60*60*24*31 +
year*60*60*24*31*12
而脱硫正在
second = X mod 60
minute = (X div 60) mod 60
hour = (X div 60*60) mod 24
day = (X div 60*60*24) mod 31
month = (X div 60*60*24*31) mod 12
year = X div 60*60*24*31*12
举一个例子:
Suppose you want to encode the date december 20, 1998, 05:33:12
So you would have
second: 12
minute: 33
hour: 5
day: 19 -> note that we encode days in the range 0..31
month: 11 -> note that we conde months in the range 0..11
year: 1998
因此,我们赞扬:
X = 12 + 33*60 + 5*60*60 +
19*60*60*24 + 11*60*60*24*31 +
1998*60*60*24*31*12
即X = 12 + 1980 + 18000 + 1641600 + 29462400 + 64217318400 = 64248442392
现在,我们就把它编码。
second = 64248442392 mod 60 = 12
minute = (64248442392 div 60) mod 60 = 33
hour = (64248442392 div 60*60) mod 24 = 5
day = (64248442392 div 60*60*24) mod 31 = 19
month = (64248442392 div 60*60*24*31) mod 12 = 11
year = 64248442392 div 60*60*24*31*12 = 1998