TimeDatetime#

class astropy.time.TimeDatetime(val1, val2, scale, precision, in_subfmt, out_subfmt, from_jd=False)[source]#

Bases: TimeUnique

Represent date as Python standard library datetime object.

Example:

>>> from astropy.time import Time
>>> from datetime import datetime
>>> t = Time(datetime(2000, 1, 2, 12, 0, 0), scale='utc')
>>> t.iso
'2000-01-02 12:00:00.000'
>>> t.tt.datetime
datetime.datetime(2000, 1, 2, 12, 1, 4, 184000)

Attributes Summary

in_subfmt

jd1

jd2

name

out_subfmt

precision

scale

Time scale.

subfmts

value

Convert to (potentially timezone-aware) datetime object.

Methods Summary

fill_value(subfmt)

Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.

set_jds(val1, val2)

Convert datetime object contained in val1 to jd1, jd2.

to_value([timezone, leap_second_strict, ...])

Convert to (potentially timezone-aware) datetime object.

Attributes Documentation

in_subfmt#
jd1#
jd2#
name = 'datetime'#
out_subfmt#
precision#
scale#

Time scale.

subfmts = ()#
value#

Convert to (potentially timezone-aware) datetime object.

If timezone is not None, return a timezone-aware datetime object.

Since the datetime class does not natively handle leap seconds, the behavior when converting a time within a leap second is controlled by the leap_second_strict argument. For example:

>>> from astropy.time import Time
>>> t = Time("2015-06-30 23:59:60.500")
>>> print(t.to_datetime(leap_second_strict='silent'))
2015-07-01 00:00:00.500000
Parameters:
timezone{tzinfo, None}, optional

If not None, return timezone-aware datetime.

leap_second_strictstr, optional

If raise (default), raise an exception if the time is within a leap second. If warn then issue a warning. If silent then silently handle the leap second.

Returns:
datetime

If timezone is not None, output will be timezone-aware.

Methods Documentation

classmethod fill_value(subfmt)#

Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.

This is used as a fill value for masked arrays to ensure that any ERFA operations on the masked array will not fail due to the masked value.

set_jds(val1, val2)[source]#

Convert datetime object contained in val1 to jd1, jd2.

to_value(timezone=None, leap_second_strict='raise', parent=None, out_subfmt=None)[source]#

Convert to (potentially timezone-aware) datetime object.

If timezone is not None, return a timezone-aware datetime object.

Since the datetime class does not natively handle leap seconds, the behavior when converting a time within a leap second is controlled by the leap_second_strict argument. For example:

>>> from astropy.time import Time
>>> t = Time("2015-06-30 23:59:60.500")
>>> print(t.to_datetime(leap_second_strict='silent'))
2015-07-01 00:00:00.500000
Parameters:
timezone{tzinfo, None}, optional

If not None, return timezone-aware datetime.

leap_second_strictstr, optional

If raise (default), raise an exception if the time is within a leap second. If warn then issue a warning. If silent then silently handle the leap second.

Returns:
datetime

If timezone is not None, output will be timezone-aware.