forked from wilsonmar/git-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.py
47 lines (35 loc) · 1.69 KB
/
temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
# temp.py
import pytz, time
from datetime import datetime, tzinfo, timedelta
from random import randint
def iso8601_utc():
class simple_utc(tzinfo):
def tzname(self,**kwargs):
return "UTC"
def utcoffset(self, dt):
return timedelta(0)
return datetime.utcnow().replace(tzinfo=simple_utc()).isoformat()
#print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
def iso8601_local():
class local_tz(tzinfo):
def utcoffset(self, dt):
ts = time.time()
offset_in_seconds = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()
return timedelta(seconds=offset_in_seconds)
return datetime.now().replace(microsecond=randint(0, 999999)).replace(tzinfo=local_tz()).isoformat()
# print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
#tz = pytz.timezone('America/Los_Angeles')
#print(datetime.fromtimestamp(1463288494, tz).isoformat())
#2016-05-14T22:01:34-07:00
#import sys
#import argparse # https://docs.python.org/2/howto/argparse.html
#import time # tzinfo, timedelta
#utc_offset_sec = time.altzone if time.localtime().tm_isdst else time.timezone
#datetime.datetime.now().replace(tzinfo=datetime.timezone(offset=utc_offset_sec)).isoformat()
#class TZ(tzinfo):
# def utcoffset(self, dt): return timedelta(minutes=-399)
#datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
#print('jenkins_secret_chrome.py' +utc_offset_sec+ '.png')