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 :: python get function docstring 
Python :: how to divide string in python 
Python :: variable bound to a set python 
Python :: python reading into a text file and diplaying items in a user friendly manner 
Python :: input check in pygame 
Python :: django pre_save get old instance 
Python :: sqlalchemy one to one foreign key 
Python :: mid-point circle drawing 
Python :: python write data to file with permissions 
Python :: shared SHMEM python 
Python :: plotting mean in density plot ggplot2 
Python :: black jack python 
Python :: threading in python 
Python :: union type python 
Python :: repeat a condition n times one by one python 
Python :: python count unique values in list 
Python :: how to omit days pandas datetime 
Python :: python dictionary delete based on value 
Python :: how to add some thing in python list 
Python :: importing time and sleep. python 
Python :: na.fill pyspark 
Python :: where is python installed windows 
Python :: python calculator source code 
Python :: all combinations 
Python :: how to play audio in python using pygame 
Python :: python getting line count 
Python :: tkinter change button foreground 
Python :: django run manage.py from python 
Python :: Total processing python 
Python :: gfg placement course 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =