Isoformat() Function Of Datetime.date Class In Python

For a datetime.date object in Python, isoformat() returns the date value in ISO 8601 format. The python example gets the date string and prints its type as well.

Date Updated 12 Jul 2019 1 min read

Function Name

isoformat

Function Signature

isoformat()

Return Value

Returns a string containing the date in ISO 8601 format.

Type

Instance method.

Overview

  • The isoformat() method returns the date value of a Python datetime.date object in ISO 8601 format.
  • The standard ISO 8601 is about date formats for Gregorian calendar. It prescribes that a calendar date to be represented using a 4-digit year followed by a two-digit month and a two-digit date. i.e., YYYY-MM-DD. Example: 2020-01-01.

Example

python
import datetime

import time

todaysDate      = datetime.date.fromtimestamp(time.time())

dateISOFormat   = todaysDate.isoformat()

print("Today's date in ISO Format:%s"%dateISOFormat)

print(type(dateISOFormat))

Output

Output
Today's date in ISO Format:2019-07-12

<class 'str'>