跳至主要內容

获取下一个完全对称日

ycyin小于 1 分钟算法&数学Python

前言

今日热点:20211202完全对称日。其实就是数学上的回文数,获取下一个完全对称日可以利用python的字符串切片判断即可。

代码

#!/usr/bin/python3
import time
now = int(time.time()) 
while (1):
    now  = now + 60*60*24
    timeStruct = time.localtime(now) 
    strTime = time.strftime("%Y%m%d", timeStruct)
    if strTime[::-1]==strTime:
        print('The next palindrome day:',strTime) #py timeR.py  --> The next palindrome day: 20300302
        break;

运行得出,20211202下一个完全对称日为20300302。