Modules
Learn how modules work in the Python programming language.
StartKey Concepts
Review core concepts you need to learn to master this subject
Date and Time in Python
Aliasing with ‘as’ keyword
Import Python Modules
random.randint()
and random.choice()
Module importing
Date and Time in Python
Date and Time in Python
import datetime
feb_16_2019 = datetime.date(year=2019, month=2, day=16)
feb_16_2019 = datetime.date(2019, 2, 16)
print(feb_16_2019) #2019-02-16
time_13_48min_5sec = datetime.time(hour=13, minute=48, second=5)
time_13_48min_5sec = datetime.time(13, 48, 5)
print(time_13_48min_5sec) #13:48:05
timestamp= datetime.datetime(year=2019, month=2, day=16, hour=13, minute=48, second=5)
timestamp = datetime.datetime(2019, 2, 16, 13, 48, 5)
print (timestamp) #2019-01-02 13:48:05
Python provides a module named datetime
to deal with dates and times.
It allows you to set date
,time
or both date
and time
using the date()
,time()
and datetime()
functions respectively, after importing the datetime
module .
Modules: Python
Lesson 1 of 1