xxxxxxxxxx
from datetime import datetime
timestamp = 1586507536367
dt_object = datetime.fromtimestamp(timestamp)
xxxxxxxxxx
from datetime import datetime
timestamp = 1553367060
dt_obj = datetime.fromtimestamp(timestamp).strftime('%d-%m-%y')
print("date:",dt_obj)
xxxxxxxxxx
from datetime import datetime
dt = datetime.strptime('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ')
print dt.strftime('%d/%m/%Y')
#------------------------------------------------------------------------
from datetime import datetime
timestamp = 1545730073
dt_obj = datetime.fromtimestamp(1140825600)
print("date_time:",dt_obj)
print("type of dt:",type(dt_obj))
xxxxxxxxxx
import datetime
now = datetime.datetime.today()
timestamp = datetime.datetime.timestamp(now)
xxxxxxxxxx
import time
ts = time.time()
// OR
import datetime;
ct = datetime.datetime.now()
ts = ct.timestamp()
xxxxxxxxxx
import time
import datetime
# date in string format
dt="23/04/2022"
# convert into the time tuple
time_tuple=datetime.datetime.strptime(dt, "%d/%m/%Y").timetuple()
print("Time tuple format ",time_tuple)
# using mktime() convert to timestamp
print("The timestamp is ",time.mktime(time_tuple))
xxxxxxxxxx
from datetime import datetime
timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)
print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))
xxxxxxxxxx
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1322697600.0
xxxxxxxxxx
import time
import datetime
s = "01/12/2011"
time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
xxxxxxxxxx
import datetime
from datetime import datetime
timestamp = pd.Timestamp('2020-5-23')