tconvert#

gwpy.time.tconvert(gpsordate: SupportsFloat) datetime[source]#
gwpy.time.tconvert(
gpsordate: date | Time | str,
) LIGOTimeGPS

Convert GPS times to ISO-format date-times and vice-versa.

Warning

This method cannot convert exact leap seconds to datetime.datetime, that object doesn’t support it, so you should consider using astropy.time.Time directly.

Parameters:
gpsordatefloat, astropy.time.Time, datetime.datetime, …

Input gps or date to convert, many input types are supported.

Returns:
datedatetime.datetime or LIGOTimeGPS

Converted gps or date.

Notes

Examples

Integers and floats are automatically converted from GPS to datetime.datetime:

>>> from gwpy.time import tconvert
>>> tconvert(0)
datetime.datetime(1980, 1, 6, 0, 0, tzinfo=datetime.timezone.utc)
>>> tconvert(1126259462.3910)
datetime.datetime(2015, 9, 14, 9, 50, 45, 391000, tzinfo=datetime.timezone.utc)

while strings are automatically converted to LIGOTimeGPS:

>>> to_gps("Sep 14 2015 09:50:45.391")
LIGOTimeGPS(1126259462, 391000000)

Additionally, a few special-case words as supported, which all return LIGOTimeGPS:

>>> tconvert("now")
>>> tconvert("today")
>>> tconvert("tomorrow")
>>> tconvert("yesterday")