Site Sponsors:
Passable 'RFC 2822' Localtime in Python 3 
Time ... you would think that it would be easy to express on a computer... What could be more natural than counting the number of seconds?

Yet after decades of computerization, we are still 'haggling over the proper way to express time!

Here is what we cobbled together while creating a client-side API for the new, R&D, AboutTime HTML Server:

import datetime
from email import utils

zdt = datetime.datetime.now() # Omits the GMT Offset
print(zdt)
zlocal = utils.localtime(zdt) # Adds the official GMT Offset
print(zlocal)
localtime = utils.format_datetime(zlocal) # RFC 2822-ish
print(localtime)

... and here is the output:

/usr/bin/python3.5 .../Python3/AboutTime_API/CreateTest.py
2017-12-13 08:02:20.817119
2017-12-13 08:02:20.817119-05:00
Wed, 13 Dec 2017 08:02:20 -0500

Then, as one becomes interested in Zulu / Server Time:

# ZULU!
zdt = datetime.datetime.utcnow() # Omits the GMT Offset
print(zdt)
zulutime = utils.format_datetime(zdt) # RFC 2822-ish
print(zulutime)

Results:

2017-12-13 13:02:20.817251
Wed, 13 Dec 2017 13:02:20 -0000

Sharing is caring!

-Randall





Google candy: GMT, UTC, Epoch time, conversion, email, RFC 822



[ add comment ]   |  permalink  |  related link

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>