Python Date strftime() Method


The strftime() Method

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

The method is called strftime(), and takes one parameter, format, to specify the format of the returned string:

Example

Display the name of the month:

import datetime

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

print(x.strftime("%B"))
Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.