Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert datetime to date python

datetime.datetime.now().date()
Comment

How to convert datetime in python

#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)
Comment

datetime convert python

# 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)
'''

Comment

PREVIOUS NEXT
Code Example
Python :: Converting time python 
Python :: python print not working 
Python :: django url with slug 
Python :: numpy add 
Python :: |safe django 
Python :: longest palindromic substring using dp 
Python :: pytest monkeypatch 
Python :: phyton "2.7" print 
Python :: what is data normalization 
Python :: python code variable declaration 
Python :: Python Pandas: Create new column out of other columns where value is not null 
Python :: run ansible playbook python 
Python :: tf dataset 
Python :: print list of list line by line python 
Python :: map dataframe 
Python :: how to use djoser signals 
Python :: session of flask 
Python :: merge sort in python 
Python :: function composition python 
Python :: TypeError: create_superuser() missing 1 required positional argument: 
Python :: check permissions django template 
Python :: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997) 
Python :: python typing union 
Python :: python string and integer concatenation 
Python :: crud python 
Python :: how to create multiple columns after applying a function in pandas column python 
Python :: Restrict CPU time or CPU Usage using python code 
Python :: get row count dataframe pandas 
Python :: python child class init 
Python :: python assertEqual tuple list 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =