Oh Snap!

Please turnoff your ad blocking mode for viewing your site content

Hit enter after type your search item

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

/
/
/
9 Views

 

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

 

READ  Python 3 Subtitles Extractor From Youtube Video Script and Downloads it as .SRT File in Windows,Mac and Linux Using BeautifulSoup4 and Click Library Full Project For Beginners

 

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

 

READ  Python 3 Script jsmin Library Example to Compress or Minify Javascript Files 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

READ  Python 3 Script to Implement Copy to Clipboard Text Using pyperclip Library Full Tutorial 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 Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Coding Shiksha 2020. All Rights Reserved.
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :