neotime.DateTime

The DateTime class is a nanosecond-precision drop-in replacement for the standard library datetime class. As such, it contains both Date and Time information and draws functionality from those individual classes. A high degree of API compatibility with the standard library classes is provided. This includes aliases for method names to allow, for example, DateTime.from_ordinal() to be called as DateTime.fromordinal().

A DateTime object is fully compatible with the Python time zone library pytz. Functions such as normalize and localize can be used in the same way as they are with the standard library classes.

Constructors and other class methods

class neotime.DateTime(year, month, day, hour=0, minute=0, second=0.0, tzinfo=None)

Regular construction of a DateTime object requires at least the year, month and day arguments to be supplied. The optional hour, minute and second arguments default to zero and tzinfo defaults to None.

While year, month, day, hour and minute accept only int() values, second can also accept a float() value. This allows sub-second values to be passed, with up to nine decimal places of precision held by the object within the second attribute.

>>> dt = DateTime(2018, 4, 30, 12, 34, 56.789123456); dt
neotime.DateTime(2018, 4, 30, 12, 34, 56.789123456)
>>> dt.second
56.789123456
classmethod DateTime.now()
classmethod DateTime.utc_now()
classmethod DateTime.from_timestamp(timestamp, tz=None)
classmethod DateTime.utc_from_timestamp(timestamp)
classmethod DateTime.from_ordinal(ordinal)
classmethod DateTime.combine(date, time)
classmethod DateTime.parse(timestamp, tz=None)
classmethod DateTime.from_clock_time(t, epoch)

Class attributes

DateTime.min
DateTime.max
DateTime.resolution

Instance attributes

dt.year
dt.month
dt.day
dt.year_month_day
dt.year_week_day
dt.year_day
dt.hour
dt.minute
dt.second
dt.tzinfo
dt.hour_minute_second

Operations

hash(dt)
dt1 == dt2
dt1 != dt2
dt1 < dt2
dt1 > dt2
dt1 <= dt2
dt1 >= dt2
dt1 + timedelta -> dt2
dt1 + duration -> dt2
dt1 - timedelta -> dt2
dt1 - duration -> dt2
dt1 - dt2 -> timedelta

Instance methods

dt.date()
dt.time()
dt.timetz()
dt.replace(year=self.year, month=self.month, day=self.day, hour=self.hour, minute=self.minute, second=self.second, tzinfo=self.tzinfo)

Return a DateTime with one or more components replaced with new values.

dt.as_timezone()
dt.utc_offset()
dt.dst()
dt.tzname()
dt.time_tuple()
dt.utc_time_tuple()
dt.to_ordinal()
dt.weekday()
dt.iso_weekday()
dt.iso_calendar()
dt.iso_format()
dt.__repr__()
dt.__str__()
dt.__format__()

Special values

neotime.Never

A DateTime instance set to 0000-00-00T00:00:00. This has a Date component equal to ZeroDate and a Time component equal to Midnight.

neotime.UnixEpoch

A DateTime instance set to 1970-01-01T00:00:00.