/ Published in: Python
date, datetime and time objects in Python have a strftime method for creating string representations in whatever format you want. (See the strftime link for the strftime syntax.)
Expand |
Embed | Plain Text
def format_date_numerical(date): """Take a date or datetime object and return a string of the form YYYY_MM_DD.""" return date.strftime("%Y_%m_%d") def format_date_pretty(date): """Take a date or datetime object and return a string of the form Thursday 15 January 2009.""" return date.strftime("%A %d %B %Y")
You need to login to post a comment.
