mwstray
mwstray

Reputation: 355

Python date formatting (0/0/0000 style)

I just have a simple question, I want to print out the date in a "0/0/0000" format, but the way that it's coming out is in a "0, 0, 0000" format. How could I change this? It has to do with this part of the code:

print(time_now.tm_mon, time_now.tm_mday, time_now.tm_year)

Thanks! Here's all of the program so far.

import calendar
from time import localtime

def timeDate():
    time_now = localtime()
    print(time_now.tm_mon, time_now.tm_mday, time_now.tm_year)
    return None

def get_calendar():
    bold = "\033[1m"
    reset = "\033[0;0m"
    cal = calendar.month(2013, 5)
    print("")
    print(bold+"Here is the calendar:"+reset)
    print("")
    print cal
    return None

Upvotes: 0

Views: 223

Answers (1)

Roland Smith
Roland Smith

Reputation: 43505

Use time.strftime to format dates.

In [16]: time.strftime('%m/%d/%Y')
Out[16]: '05/16/2013'

Upvotes: 2

Related Questions