레이블이 파이썬 오늘 날짜 출력 python today string example인 게시물을 표시합니다. 모든 게시물 표시
레이블이 파이썬 오늘 날짜 출력 python today string example인 게시물을 표시합니다. 모든 게시물 표시

2012년 3월 10일 토요일

[Python] 오늘 날짜 출력 예제

import os
import datetime

# get today and try to return as string
today = datetime.datetime.now()

print "Current year: %d" % today.year
print "Current year: %d" % today.month
print "Current year: %d" % today.day

month_str = str(today.month)
day_str = str(today.day)

# months manipulation
if len(month_str) == 1:
month_str = "0" + month_str
else:
month_str = month_str

# day manipulation
if len(day_str) == 1:
day_str = "0" + day_str
else:
day_str = day_str

today_str = str(today.year) + month_str + day_str
tm_str = str(today.year) + month_str

print today_str