[Numpy-discussion] timezones and datetime64

Chris Barker - NOAA Federal chris.barker at noaa.gov
Thu Apr 4 14:56:41 EDT 2013


On Thu, Apr 4, 2013 at 10:54 AM, Francesc Alted <francesc at continuum.io> wrote:

> That makes a difference.  This can be specially important for creating
> user-defined time origins:
>
> In []: np.array(int(1.5e9), dtype='datetime64[s]') + np.array(1,
> dtype='timedelta64[ns]')
> Out[]: numpy.datetime64('2017-07-14T04:40:00.000000001+0200')

but that's worthless if you try it higher-resolution:

In [40]: np.array(int(1.5e9), dtype='datetime64[s]')
Out[40]: array(datetime.datetime(2017, 7, 14, 2, 40), dtype='datetime64[s]')

# Start at 2017

# add a picosecond:
In [41]: np.array(int(1.5e9), dtype='datetime64[s]') + np.array(1,
dtype='timedelta64[ps]')
Out[41]: numpy.datetime64('1970-03-08T22:55:30.029526319105-0800')

# get 1970???

And even with nanoseconds, given the leap-second issues, etc, you
really wouldn't want to do this anyway -- rather, keep your epoch
close by.

Now that I think about it -- being able to set your epoch could lessen
the impact of leap-seconds for second-resolution as well.

-Chris

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list