This is a Python binding to the C++ class Mantid::Kernel::DateAndTime.
The equivalent object in python is numpy.datetime64. The two classes have a different EPOCH. Note that mantid.kernel.DateAndTime uses the GPS epoch of 1990, where numpy.datetime64 uses the unix epoch of 1970. For that reason, there is an additional method mantid.kernel.DateAndTime.to_datetime64().
To convert an array of mantid.kernel.DateAndTime, analgous to what mantid.kernel.FloatTimeSeriesProperty.times() does internally, use the code:
times = np.array(times, dtype=np.int64) * np.timedelta64(1,'ns') + np.datetime64('1990-01-01T00:00')
With numpy.datetime64, finding the number of seconds between two times is simply
diff = (timeArray[-1]-timeArray[0]) / np.timedelta64(1, 's')
For converting numpy.datetime64 data to a string for the default facilty, use numpy.datetime_as_string() explicitly (assuming the times are a variable named times)
import pytz
tz = pytz.timezone(ConfigService.getFacility().timezone())
times = numpy.datetime_as_string(times, timezone=tz)
This is how numpy internally converts numpy.datetime64 to strings for printing, but the selection of timezone is explicit (using pytz) to allow for matching where the data was recorded rather than the system’s timezone.
How strings are interpreted by numpy.datetime64 changed in version 1.11. Before this point, a string without timezone designation was assumed to be in local timezone. After this point it is assumed to be in UTC. Additionally as of version 1.11, NumPy started warning if a string was supplied with timezone designation. This means that on rhel7 (in EDT)
repr(np.datetime64('1990-01-01T00:00Z'))
repr(np.datetime64('1990-01-01T00:00'))
result in "numpy.datetime64('1989-12-31T19:00-0500')" and "numpy.datetime64('1990-01-01T00:00-0500')" respectively. However, in “newer” python results "numpy.datetime64('1990-01-01T00:00')", but the first version results in a DeprecationWarning.
Construct from an ISO8601 string
Converts the time into ISO8601Standard and returns the string
Convert to numpy.datetime64
Since 1990-01-01T00:00
Since 1990-01-01T00:00