As you may have heard, 02-02-2020 is a very “palindromic” day today. Especially so in that in either date formatting you use, the numbers are the same backward as forward (assuming you use 02 not “2” that is). Matt Parker was quite excited, in fact he was beside himself in his latest math video:
Now you may be thinking… awesome… but is this also a palindrome date for computers? and is it really that long until the next palindrome day? Many computers use the epoch time in file attributes or operating systems – which is the number of seconds since 1970. As of today, we have passed 1580660851, which is…. Feb 2 2020! This day is more of a palindrome than I thought!
This brings up the question, what other palindrome days are coming up? Can we easily see days coming up? Sure we can, with some time functions in Python! to get the current timestamp in seconds you can use:
>>> int(time.time())
1580684799
Now to get some palindrome datetimes we need to just get values for the first part, then reverse it to get a full palindrome. A special feature of the array slicing allows you do do this:
>>> 'abcdef'[0:6] #equivalent to [0:6:1], equivalent to [0::], [0::1], [::1]
'abcdef'
>>> 'abcdef'[::2] #everyother, equivalent to [0:-1:2]
'ace'
>>> 'abcdef'[::-2] #backward 2 at a time, equivalent to [5:0:-2]
'fdb'
>> 'abcdef'[::-1] #reversed!
'fedcba'
The index lookup is quite advanced, and kind of weird compared to other languages… but it makes it easy to reverse an array or string with [::-1] after the array. As you can read in the time documentation strftime turns a date time structure to a time string describing the date and time, so you can get the current time like so:
>>> import time
>>> time.strftime('%A %B %d %H:%M',time.localtime(time.time()))
'Sunday February 02 15:23'
So putting those together, let’s get the date timestamps, starting with today’s, that are palindromes, that is, have first digits the same as reversed last digits:
import time
firstdigits = 15806
while firstdigits < 18000:
#Make a palindrome, that is the date with reversed digits:
epochtimestamp = str(firstdigits)+str(firstdigits)[::-1]
print(epochtimestamp)
print( time.strftime(' = %A %B %d, %Y %H:%M', time.localtime(int(epochtimestamp))) )
firstdigits += 1
Now run this and it will tell you exactly when the “palindrome timestamp” happens, in your local time zone. As you can see, tomorrow has a palindrome, so does the day after… in fact there are many palindrome timestamps in epoch timestamps… which is probably why no software developers told me about this “palindrome day”… in computer time, just about every other day has a “palindrome time”!
1580660851
= Sunday February 02, 2020 08:27
1580770851
= Monday February 03, 2020 15:00
1580880851
= Tuesday February 04, 2020 21:34
1580990851
= Thursday February 06, 2020 04:07
1581001851
= Thursday February 06, 2020 07:10
1581111851
= Friday February 07, 2020 13:44
1581221851
= Saturday February 08, 2020 20:17
1581331851
= Monday February 10, 2020 02:50
1581441851
= Tuesday February 11, 2020 09:24
1581551851
= Wednesday February 12, 2020 15:57
1581661851
= Thursday February 13, 2020 22:30
1581771851
= Saturday February 15, 2020 05:04
1581881851
= Sunday February 16, 2020 11:37
1581991851
= Monday February 17, 2020 18:10
1582002851
= Monday February 17, 2020 21:14
1582112851
= Wednesday February 19, 2020 03:47
1582222851
= Thursday February 20, 2020 10:20
1582332851
= Friday February 21, 2020 16:54
1582442851
= Saturday February 22, 2020 23:27
1582552851
= Monday February 24, 2020 06:00
1582662851
= Tuesday February 25, 2020 12:34
1582772851
= Wednesday February 26, 2020 19:07
1582882851
= Friday February 28, 2020 01:40
1582992851
= Saturday February 29, 2020 08:14
1583003851
= Saturday February 29, 2020 11:17
1583113851
= Sunday March 01, 2020 17:50
1583223851
= Tuesday March 03, 2020 00:24
1583333851
= Wednesday March 04, 2020 06:57
1583443851
= Thursday March 05, 2020 13:30
1583553851
= Friday March 06, 2020 20:04
1583663851
= Sunday March 08, 2020 03:37
1583773851
= Monday March 09, 2020 10:10
1583883851
= Tuesday March 10, 2020 16:44
1583993851
= Wednesday March 11, 2020 23:17
1584004851
= Thursday March 12, 2020 02:20
1584114851
= Friday March 13, 2020 08:54
1584224851
= Saturday March 14, 2020 15:27
1584334851
= Sunday March 15, 2020 22:00
1584444851
= Tuesday March 17, 2020 04:34
1584554851
= Wednesday March 18, 2020 11:07
1584664851
= Thursday March 19, 2020 17:40
1584774851
= Saturday March 21, 2020 00:14
1584884851
= Sunday March 22, 2020 06:47
1584994851
= Monday March 23, 2020 13:20
1585005851
= Monday March 23, 2020 16:24
1585115851
= Tuesday March 24, 2020 22:57
1585225851
= Thursday March 26, 2020 05:30
1585335851
= Friday March 27, 2020 12:04
1585445851
= Saturday March 28, 2020 18:37
1585555851
= Monday March 30, 2020 01:10
1585665851
= Tuesday March 31, 2020 07:44
1585775851
= Wednesday April 01, 2020 14:17
1585885851
= Thursday April 02, 2020 20:50
1585995851
= Saturday April 04, 2020 03:24
1586006851
= Saturday April 04, 2020 06:27
1586116851
= Sunday April 05, 2020 13:00
1586226851
= Monday April 06, 2020 19:34
1586336851
= Wednesday April 08, 2020 02:07
1586446851
= Thursday April 09, 2020 08:40
1586556851
= Friday April 10, 2020 15:14
1586666851
= Saturday April 11, 2020 21:47
1586776851
= Monday April 13, 2020 04:20
1586886851
= Tuesday April 14, 2020 10:54
1586996851
= Wednesday April 15, 2020 17:27
1587007851
= Wednesday April 15, 2020 20:30
1587117851
= Friday April 17, 2020 03:04
1587227851
= Saturday April 18, 2020 09:37
1587337851
= Sunday April 19, 2020 16:10
1587447851
= Monday April 20, 2020 22:44
1587557851
= Wednesday April 22, 2020 05:17
1587667851
= Thursday April 23, 2020 11:50
1587777851
= Friday April 24, 2020 18:24
1587887851
= Sunday April 26, 2020 00:57
1587997851
= Monday April 27, 2020 07:30
1588008851
= Monday April 27, 2020 10:34
1588118851
= Tuesday April 28, 2020 17:07
1588228851
= Wednesday April 29, 2020 23:40
1588338851
= Friday May 01, 2020 06:14
1588448851