Mercurial > hg > config
diff python/epoch2date.py @ 665:93afa559ce77
update
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 16 Apr 2014 17:02:42 -0700 |
parents | dea3258f005f |
children | fe6afbc1a38e |
line wrap: on
line diff
--- a/python/epoch2date.py Mon Apr 07 19:24:57 2014 -0700 +++ b/python/epoch2date.py Wed Apr 16 17:02:42 2014 -0700 @@ -9,12 +9,22 @@ import time def main(args=sys.argv[1:]): + """CLI""" + # parse command line parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('seconds_since_epoch', help="seconds since epoch input") + parser.add_argument('seconds_since_epoch', + type=float, nargs='?', default=time.time(), + help="seconds since epoch input [DEFAULT: %(default)s]") options = parser.parse_args(args) - + # produce a datetime + dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch) + dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch) + + # output + print (dt) + print (dt2) if __name__ == '__main__': main()