Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sun, 06 Nov 1994 08:49:37 GMT
- from wsgiref.handlers import format_date_time
- from datetime import datetime
- from time import mktime
- now = datetime.now()
- stamp = mktime(now.timetuple())
- print format_date_time(stamp) #--> Wed, 22 Oct 2008 10:52:40 GMT
- from email.utils import formatdate
- from datetime import datetime
- from time import mktime
- now = datetime.now()
- stamp = mktime(now.timetuple())
- print formatdate(
- timeval = stamp,
- localtime = False,
- usegmt = True
- ) #--> Wed, 22 Oct 2008 10:55:46 GMT
- import locale, datetime
- locale.setlocale(locale.LC_TIME, 'en_US')
- datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
- from datetime import datetime
- from babel.dates import format_datetime
- now = datetime.utcnow()
- format = 'EEE, dd LLL yyyy hh:mm:ss'
- print format_datetime(now, format, locale='en') + ' GMT'
- def httpdate(dt):
- """Return a string representation of a date according to RFC 1123
- (HTTP/1.1).
- The supplied date must be in UTC.
- """
- weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][dt.weekday()]
- month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec"][dt.month - 1]
- return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (weekday, dt.day, month,
- dt.year, dt.hour, dt.minute, dt.second)
- from email.utils import formatdate
- print formatdate(timeval=None, localtime=False, usegmt=True)
- Wed, 22 Oct 2008 10:32:33 GMT
- >>> locale.setlocale(locale.LC_TIME, 'en_US')
- 'en_US'
- >>> datetime.datetime.now().strftime(locale.nl_langinfo(locale.D_T_FMT))
- 'Wed 22 Oct 2008 06:05:39 AM '
- def httpdate(dt):
- """Return a string representation of a date according to RFC 1123
- (HTTP/1.1).
- The supplied date must be in UTC.
- """
- weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][dt.weekday()]
- month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec"][dt.month - 1]
- return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (weekday, dt.day, month,
- dt.year, dt.hour, dt.minute, dt.second)
Add Comment
Please, Sign In to add comment