Python 3 Datetime Module Formatting Dates and Time Full Example For Beginners

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

See also  Python 3 Pandas DataFrame.assign() Method Script to Add New Columns to Existing DataFrame Full Example Project For Beginners

 

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

 

See also  Python 3 Tkinter Script to Display International Countries Information in GUI Desktop App Through JSON Module Full Project For Beginners

 

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

See also  Python 3 WxPython Horizontal Range Slider Class Widget With Values Example in GUI Desktop App Full Project For Beginners

 

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)

 

 

 

Leave a Reply