Mercurial > hg > config
annotate python/epoch2date.py @ 668:ef2762b1f7e8
note to self about fun tzinfo to fix in a year
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Thu, 17 Apr 2014 13:04:26 -0700 |
| parents | af95905ca177 |
| children | bcf5781b615e |
| rev | line source |
|---|---|
| 636 | 1 #!/usr/bin/env python |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 667 | 4 """ |
| 5 conversion between epoch and dates | |
| 6 | |
| 7 https://docs.python.org/2/library/time.html | |
|
668
ef2762b1f7e8
note to self about fun tzinfo to fix in a year
Jeff Hammel <k0scist@gmail.com>
parents:
667
diff
changeset
|
8 https://docs.python.org/2/library/datetime.html |
|
ef2762b1f7e8
note to self about fun tzinfo to fix in a year
Jeff Hammel <k0scist@gmail.com>
parents:
667
diff
changeset
|
9 http://bugs.python.org/issue7229 |
| 667 | 10 """ |
| 11 | |
| 636 | 12 import argparse |
| 13 import datetime | |
| 14 import os | |
| 15 import subprocess | |
| 16 import sys | |
| 17 import time | |
| 18 | |
| 19 def main(args=sys.argv[1:]): | |
| 665 | 20 """CLI""" |
| 636 | 21 |
| 665 | 22 # parse command line |
| 636 | 23 parser = argparse.ArgumentParser(description=__doc__) |
| 665 | 24 parser.add_argument('seconds_since_epoch', |
| 25 type=float, nargs='?', default=time.time(), | |
| 26 help="seconds since epoch input [DEFAULT: %(default)s]") | |
| 636 | 27 options = parser.parse_args(args) |
| 28 | |
| 665 | 29 # produce a datetime |
| 30 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch) | |
| 31 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch) | |
| 32 | |
| 33 # output | |
| 666 | 34 print ("{} seconds since epoch".format(options.seconds_since_epoch)) |
| 35 print ("{} {}".format(dt, time.tzname[time.daylight])) | |
| 36 print ("{} UTC".format(dt2)) | |
| 636 | 37 |
| 38 if __name__ == '__main__': | |
| 39 main() |
