Answers for "py datetime"

27

string to date python

import datetime

date_time_str = '2018-06-29 08:15:27.243860'
date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')

print('Date:', date_time_obj.date())
print('Time:', date_time_obj.time())
print('Date-time:', date_time_obj)
Posted by: Guest on June-01-2020
10

strftime python

date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
Posted by: Guest on January-22-2021
26

datetime python

from datetime import datetime as d
date = d.now()
print(date.strftime("%Y-%m-%d %H:%M:%S"))
Posted by: Guest on December-09-2020
5

python datetime module

import datetime as d
time = d.datetime.now()
time = time.strftime("%Y-%m-%d  %H:%M:%S")
           #year-#month-#date  #hour:#minure:#second
print(time)
Posted by: Guest on May-06-2021
-3

datetime python

>>> timedelta(hours=-5)
datetime.timedelta(days=-1, seconds=68400)
>>> print(_)
-1 day, 19:00:00
Posted by: Guest on February-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language