2019-06-12 05:41:31 +00:00
|
|
|
import datetime
|
2020-07-08 05:17:40 +00:00
|
|
|
import re
|
2019-06-12 05:41:31 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
EPOCH = datetime.datetime(
|
|
|
|
year=1993,
|
|
|
|
month=9,
|
|
|
|
day=1,
|
|
|
|
)
|
|
|
|
|
2020-07-08 05:17:40 +00:00
|
|
|
def strftime(format, tpl=None):
|
|
|
|
now = datetime.datetime.now()
|
2019-06-12 05:41:31 +00:00
|
|
|
diff = now - EPOCH
|
2020-07-08 05:17:40 +00:00
|
|
|
|
|
|
|
day = str(diff.days + 1)
|
|
|
|
day_of_year = str(244 + diff.days)
|
|
|
|
|
|
|
|
changes = {
|
|
|
|
r'%b': 'Sep',
|
|
|
|
r'%B': 'September',
|
|
|
|
r'%d': day,
|
|
|
|
r'%-d': day,
|
|
|
|
r'%j': day_of_year,
|
|
|
|
r'%-j': day_of_year,
|
|
|
|
r'%m': '09',
|
|
|
|
r'%-m': '9',
|
|
|
|
r'%Y': '1993',
|
|
|
|
r'%y': '93',
|
|
|
|
}
|
|
|
|
for (key, value) in changes.items():
|
|
|
|
key = r'(?<!%)' + key
|
|
|
|
format = re.sub(key, value, format)
|
|
|
|
|
|
|
|
if tpl is not None:
|
|
|
|
return time.strftime(format, tpl)
|
|
|
|
else:
|
|
|
|
return time.strftime(format)
|
2019-06-12 05:41:31 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-08 05:17:40 +00:00
|
|
|
print(strftime('%Y-%m-%d %H:%M:%S'))
|