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
|
|
8 """
|
|
9
|
636
|
10 import argparse
|
|
11 import datetime
|
|
12 import os
|
|
13 import subprocess
|
|
14 import sys
|
|
15 import time
|
|
16
|
|
17 def main(args=sys.argv[1:]):
|
665
|
18 """CLI"""
|
636
|
19
|
665
|
20 # parse command line
|
636
|
21 parser = argparse.ArgumentParser(description=__doc__)
|
665
|
22 parser.add_argument('seconds_since_epoch',
|
|
23 type=float, nargs='?', default=time.time(),
|
|
24 help="seconds since epoch input [DEFAULT: %(default)s]")
|
636
|
25 options = parser.parse_args(args)
|
|
26
|
665
|
27 # produce a datetime
|
|
28 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch)
|
|
29 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch)
|
|
30
|
|
31 # output
|
666
|
32 print ("{} seconds since epoch".format(options.seconds_since_epoch))
|
|
33 print ("{} {}".format(dt, time.tzname[time.daylight]))
|
|
34 print ("{} UTC".format(dt2))
|
636
|
35
|
|
36 if __name__ == '__main__':
|
|
37 main()
|