1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
import time
from datetime import datetime
class UnifyDateStamp(object):
def __init__(self, tz):
self.tz = tz
self.set_datetime_values()
def reset(self):
self.set_datetime_values()
def set_datetime_values(self):
if self.tz:
self.datenow = datetime.utcnow()
else:
self.datenow = datetime.now(tz=None)
self.chrono = time.clock()
self.isochrono = datetime.isoformat(datetime.utcfromtimestamp(self.chrono))
dn = self.datenow.replace(microsecond=0)
self.unitime = datetime.strftime(dn, '%H:%M:%S')
self.unidate = datetime.strftime(dn, '%d/%m/%y')
self.unifulldate = datetime.isoformat(dn)
udf = UnifyDateStamp(False)
print('datenow: %s\nchrono: %s\nisochrono: %s\nunitime: %s\nunidate: %s\nunifulldate: %s'
%(udf.datenow, udf.chrono, udf.isochrono, udf.unitime, udf.unidate, udf.unifulldate))
udf.reset()
print('------------------------------------------')
print('datenow: %s\nchrono: %s\nisochrono: %s\nunitime: %s\nunidate: %s\nunifulldate: %s'
%(udf.datenow, udf.chrono, udf.isochrono, udf.unitime, udf.unidate, udf.unifulldate))
print('------------------------------------------')
udf = UnifyDateStamp(True)
print('datenow: %s\nchrono: %s\nisochrono: %s\nunitime: %s\nunidate: %s\nunifulldate: %s'
%(udf.datenow, udf.chrono, udf.isochrono, udf.unitime, udf.unidate, udf.unifulldate)) |
Partager