to_gps#

gwpy.time.to_gps(
t: LIGOTimeGPSLike | SupportsFloat | date | Time | str,
*,
tzinfo: tzinfo = datetime.timezone.utc,
) LIGOTimeGPS[source]#

Convert any input date/time into a LIGOTimeGPS.

Any input object that can be cast as a Time (with str going through the datetime.datetime) are acceptable.

Parameters:
tfloat, datetime, Time, str

The input time, any object that can be converted into a LIGOTimeGPS, Time, or datetime, is acceptable.

tzinfodatetime.tzinfo,

Timezone information to attach to tuple inputs that become datetime.datetime objects. Defaults to datetime.UTC.

Returns:
gpsLIGOTimeGPS

The number of GPS seconds (non-integer) since the start of the epoch (January 6 1980).

Raises:
TypeError

If a str input cannot be parsed as a datetime.datetime.

ValueError

If the input cannot be cast as a Time or LIGOTimeGPS.

Examples

>>> to_gps("Jan 1 2017")
LIGOTimeGPS(1167264018, 0)
>>> to_gps("Sep 14 2015 09:50:45.391")
LIGOTimeGPS(1126259462, 391000000)
>>> import datetime
>>> to_gps(datetime.datetime(2017, 1, 1))
LIGOTimeGPS(1167264018, 0)
>>> from astropy.time import Time
>>> to_gps(Time(57754, format="mjd"))
LIGOTimeGPS(1167264018, 0)