from datetime import datetime
datetime_str = '09/19/18 13:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
print(type(datetime_object))
print(datetime_object) # printed in default format
date_str = '09-19-2018'
date_object = datetime.strptime(date_str, '%m-%d-%Y').date()
print(type(date_object))
print(date_object) # printed in default formatting
datetime.datetime.now().date()
#How to convert datetime in python like below:
df.Start_Time
# 2016-02-08 00:37:08
# 2016-02-08 05:56:20
df.Start_Time = pd.to_datetime(df.Start_Time)
# input: 07:40:01PM
# output: 19:40:01
# First System:
def timeConversion(s):
period = s[-2:]
time = s[:-2]
hour = int(time[:2])
if period == 'PM' and hour < 12:
time = str(hour + 12) + time[2:]
if period == 'AM' and hour == 12:
time = '00' + time[2:]
return time
s = input()
print(timeConversion(s))
# second code and use to module:
"""
from datetime import*
def timeConversion(s):
return datetime.strftime(datetime.strptime(s, "%I:%M:%S%p"), "%H:%M:%S")
if __name__ == '__main__':
s = input()
print(timeConversion(s))
"""
# 3rd code and not used module.
'''
time = input() # time = input time.
sp = time.split(':') # sp = split the ":"
if 'PM' in sp[2]:
sp[0] = int(sp[0])+12
sp[2] = sp[2].rstrip('PM')
elif 'AM' in sp[2]:
sp[2] = sp[2].rstrip('AM')
if sp[0] == '12':
sp[0] = "0"
con_time = '' # con_time = convert time.
for i in range(2):
con_time += str(sp[i])+':'
con_time += sp[2]
print(con_time)
'''