Python 3 Datetime Module Formatting Dates and Time Full Example For Beginners
Welcome folks today in this post we will be formatting
dates in terms of time in python using the built in module called as datetime
. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
Formatting Time
app.py
import datetime
tm = datetime.time(1, 50, 20, 133257)
print('Time tm is ',
tm.hour, ' hours ',
tm.minute, ' minutes ',
tm.second, ' seconds and ',
tm.microsecond, ' microseconds' )
In the first example we are formatting the time in terms of hours
and minutes
and seconds
as shown below
Formatting Dates
Now we will be formatting dates
in terms of days
and months
and years
as shown below
app.py
import datetime
date = datetime.date(2018, 5, 12)
print('Date date is ', date.day,
' day of ', date.month,
' of the year ', date.year)