fromisoformat() Function Of Datetime.date Class In Python
Last Updated :
23 Aug, 2021
The fromisoformat() function is used to constructs a date object from a specified string that contains a date in ISO format. i.e., yyyy-mm-dd.
Syntax: @classmethod fromisoformat(date_string)
Parameters: This function accepts a parameter which is illustrated below:
- date_string: This is the specified ISO format i.e., yyyy-mm-dd date string whose date object is going to be constructed.
Return values: This function returns a date object constructed from the specified ISO format date string.
Example 1: Getting a date object from a specified string that contains date in ISO format. i.e., yyyy-mm-dd
Python3
import datetime
Date = "2012-10-12" ;
New_date = datetime.date.fromisoformat(Date);
print ( "The constructed date object is: %s" % New_date);
|
Output:
The constructed date object is: 2012-10-12
Example 2: Get the newly created date object for the specified date.
Python3
from datetime import date
print (date.fromisoformat( '2020-10-09' ))
|
Output:
2020-10-09
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...