Mercurial > hg > config
annotate python/epoch2date.py @ 672:0eff3f3658ed
STUB: python/mountusb.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 05 May 2014 01:47:27 -0700 |
parents | bcf5781b615e |
children | 1b8ea91f00a0 |
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 |
667 | 9 """ |
10 | |
669 | 11 # TODO: tz info |
12 #http://bugs.python.org/issue7229 | |
13 # http://stackoverflow.com/questions/13218506/how-to-get-system-timezone-setting-and-pass-it-to-pytz-timezone | |
14 | |
15 | |
636 | 16 import argparse |
17 import datetime | |
18 import os | |
19 import subprocess | |
20 import sys | |
21 import time | |
22 | |
23 def main(args=sys.argv[1:]): | |
665 | 24 """CLI""" |
636 | 25 |
665 | 26 # parse command line |
636 | 27 parser = argparse.ArgumentParser(description=__doc__) |
665 | 28 parser.add_argument('seconds_since_epoch', |
29 type=float, nargs='?', default=time.time(), | |
30 help="seconds since epoch input [DEFAULT: %(default)s]") | |
636 | 31 options = parser.parse_args(args) |
32 | |
665 | 33 # produce a datetime |
34 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch) | |
35 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch) | |
36 | |
37 # output | |
666 | 38 print ("{} seconds since epoch".format(options.seconds_since_epoch)) |
39 print ("{} {}".format(dt, time.tzname[time.daylight])) | |
40 print ("{} UTC".format(dt2)) | |
636 | 41 |
42 if __name__ == '__main__': | |
43 main() |