How to convert string which I need to UTC? 06-09-2019 14:34 to 06/09/2019 14:34
date2 = datetime.datetime.strptime(context.beginning_date_attribute, '%d/%m/%Y %H:%M')
this code produces 2019-09-06 14:45:00 and I dont want seconds also here
How to convert string which I need to UTC? 06-09-2019 14:34 to 06/09/2019 14:34
date2 = datetime.datetime.strptime(context.beginning_date_attribute, '%d/%m/%Y %H:%M')
this code produces 2019-09-06 14:45:00 and I dont want seconds also here
I'm not sure what context.beginning_date_attribute is, but here is how to reformat your timestamp.
from datetime import datetime
GMT_timestamp = datetime.utcnow()
print (GMT_timestamp)
# outputs
2019-09-06 14:05:22.215443
# milliseconds removed from GMT timestamp
reformatted_GMT_timestamp = GMT_timestamp.strftime('%Y-%m-%d %H:%M')
print (reformatted_GMT_timestamp)
# outputs
2019-09-06 14:05
reformatted_timestamp = datetime.strptime('2019-09-06 14:05:22.215443', '%Y-%m-%d
%H:%M:%S.%f').strftime('%d/%m/%Y %H:%M')
print (reformatted_timestamp)
# outputs
06/09/2019 14:05
You can use it like this:
from datetime import datetime
# current date and time
now = datetime.now()
s1 = now.strftime("%m/%d/%Y, %H:%M:%S")
# mm/dd/YY H:M:S format