nstime2timestr

pymseed.nstime2timestr(nstime, timeformat=TimeFormat.ISOMONTHDAY_Z, subsecond=SubSecond.NANO_MICRO_NONE)[source]

Convert a nanosecond timestamp to a date-time string

The returned string is a subset of the RFC 3339 (ISO 8601 profile) and always in UTC (Z suffix optional).

timeformat selects the overall layout via TimeFormat (ISO month-day with T or space, optional trailing Z, SEED ordinal day-of-year, Unix epoch seconds, or nanosecond epoch). The default is ISOMONTHDAY_Z (YYYY-MM-DDThh:mm:ss[.fraction]Z).

subsecond selects how fractional seconds are shown via SubSecond: fixed none / micro / nano resolution, or conditional forms that omit trailing zero fractions. The default, NANO_MICRO_NONE, uses nanoseconds when needed, otherwise microseconds when needed, otherwise no fractional part.

Examples

>>> from pymseed import nstime2timestr, timestr2nstime, TimeFormat, SubSecond
>>> t = timestr2nstime("2024-03-15T10:30:00.123456789Z")
>>> nstime2timestr(t)
'2024-03-15T10:30:00.123456789Z'
>>> nstime2timestr(t, subsecond=SubSecond.MICRO)
'2024-03-15T10:30:00.123456Z'
>>> nstime2timestr(t, timeformat=TimeFormat.ISOMONTHDAY_SPACE_Z, subsecond=SubSecond.NONE)
'2024-03-15 10:30:00Z'
Parameters:
Return type:

str