strftime() Method

Total Post:113


 392  View(s)
Rate this:

How to use time and date function in python ?

  1. Re: strftime() Method

    Python Date: in python data type are not created but we can import a module with dates as date objects in that sequence.Import datetime module and display current date: 

    import datetime 
    x =
    2018-07-06 2:44:07.670539

    The date having year, month, day, hour, minute, second, microsecond. The datetime module has many methods to return information about the date object. Return the year and name of weekday: 

    import datetime 
    x =

    Creating Date Objects :

    you can use the datetime() class (constructor) of the datetime module for creating a date.  The datetime() class requires three parameters to create a date: year, month, day. 

    Create a date object: 

    import datetime 
    x = datetime.datetime(2020,6,20)

    The strftime() Method: 

    The datetime object has a method for formatting date objects into readable strings. 

    Display the name of the month: 

    import datetime 
    x = datetime.datetime(2018, 6, 1)


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.