ADVERTISEMENT
ADVERTISEMENT

Python date isoformat() Method with Example

Python date.isoformat() Method: Here, we are going to learn about the isoformat() method of date class in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on April 29, 2020

Python date.isoformat() Method

date.isoformat() method is used to manipulate objects of date class of module datetime.

It uses a date class object and returns a string representing the date in ISO 8601 format, YYYY-MM-DD. The International Standard for the representation of dates and times is ISO 8601. It was designed to provide a  format of date and time representation free from any ambiguity. The format provides a standard approach and has the following rules:

  1. Year first, followed by month, then the day, each separated by a hyphen ("-")
  2. Numbers less than 10 preceded by a leading zero

Module:

    import datetime

Class:

    from datetime import date

Syntax:

    isoformat()

Parameter(s):

  • None

Return value:

The return type of this method is a string in ISO 8601 format of the date.

Example:

## importing date class
from datetime import date

## Creating an instance
x = date.today()
d = x.isoformat()
print("Normal format:",x)
print("ISO 8601 format:", d)
print()

x = date(2020,10,1)
print("Date 2020/10/1 in ISO 8601 format:", x.isoformat())
print()

x = date(200,10,12)
print("Date 200/10/12 in ISO 8601 format:", x.isoformat())
print()

x = date(1,1,1)
print("Date 1/1/1 in ISO 8601 format:", x.isoformat())

Output

Normal format: 2020-04-29
ISO 8601 format: 2020-04-29

Date 2020/10/1 in ISO 8601 format: 2020-10-01

Date 200/10/12 in ISO 8601 format: 0200-10-12

Date 1/1/1 in ISO 8601 format: 0001-01-01
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.