timestr2nstime

pymseed.timestr2nstime(timestr)[source]

Convert a date-time string to nanoseconds since Unix epoch

The time string is parsed as subset of the RFC 3339 (ISO 8601 profile) format. The time string must be in UTC (Z suffix optional), other time zones are not supported.

Examples

>>> from pymseed import timestr2nstime
>>> timestr2nstime("2024-03-15T10:30:00.123456789Z")
1710498600123456789
>>> timestr2nstime("1964-03-28T03:36:14Z")
-181859026000000000
>>> timestr2nstime("1970-01-01T00:00:00Z")
0
>>> timestr2nstime("not-a-time")
Traceback (most recent call last):
    ...
ValueError: Invalid time string: 'not-a-time'
>>> timestr2nstime(42)
Traceback (most recent call last):
    ...
TypeError: timestr must be str; got int
Raises:
  • TypeError – If timestr is not a str.

  • ValueError – If timestr cannot be parsed as a date-time string.

Parameters:

timestr (str)

Return type:

int