I have been analyzing the JSON file generated using chrome://webrtc-internal, while running webrtc. I'm trying to find the matching timezone of the startTime in the following result:
'RTCVideoSource_6-width': {
'startTime': '2021-04-14T07:09:33.163Z',
'endTime': '2021-04-14T07:14:12.161Z',
'values': '[1920,1920,1920,1920,1920,1920,1920,1920,1920]'},
I tried UTC timezone to find the corresponding timestamp in my timezone but didn't succeed.
yourdate = dateutil.parser.parse(RTCVideoSource_6-width['startTime'])
startTime_utc = yourdate.replace(tzinfo=pytz.UTC)
startTime_hk=startTime_utc.astimezone(pytz.timezone("Asia/Hong_Kong")) #astimezone method
#since 1970
startAge_utc = datetime.datetime(1970,1,1).replace(tzinfo=pytz.UTC)
startAge_hk=startAge_utc.astimezone(pytz.timezone("Asia/Hong_Kong")) #astimezone method
start_in_seconds = int((startTime_hk- startAge_hk).total_seconds())
When I compared now()
as a timestamp in seconds, I got values with a relatively big difference,
1618384173
and 1618383543
.
What is the timezone used in chrome://webrtc-internal stats? Is my conversion method correct?
See ISO8601: you have UTC date/time (Z = zulu = UTC). See How do I parse an ISO 8601-formatted date? how to parse. Unix time (seconds since 1970-01-01) on the other hand always (should) refer to UTC (e.g. startTime_utc and startTime_hk must give the same timestamp!). Note: datetime objects have a timestamp method.
EX:
from datetime import datetime
from zoneinfo import ZoneInfo # Python 3.9+
d = {'startTime': '2021-04-14T07:09:33.163Z',
'endTime': '2021-04-14T07:14:12.161Z',
'values': '[1920,1920,1920,1920,1920,1920,1920,1920,1920]'}
startTime_utc = datetime.fromisoformat(d['startTime'].replace('Z', '+00:00'))
print(repr(startTime_utc))
# datetime.datetime(2021, 4, 14, 7, 9, 33, 163000, tzinfo=datetime.timezone.utc)
print(startTime_utc.timestamp())
# 1618384173.163
startTime_HK = startTime_utc.astimezone(ZoneInfo('Asia/Hong_Kong'))
print(repr(startTime_HK))
# datetime.datetime(2021, 4, 14, 15, 9, 33, 163000, tzinfo=zoneinfo.ZoneInfo(key='Asia/Hong_Kong'))
print(startTime_HK.timestamp())
# 1618384173.163