bundles / numpy latest / numpy / _core / _multiarray_umath / datetime_as_string
built-in
numpy._core._multiarray_umath:datetime_as_string
Signature
built-in
datetime_as_string ( arr , unit = None , timezone = naive , casting = same_kind ) Summary
Convert an array of datetimes into an array of strings.
Parameters
arr: array_like of datetime64The array of UTC timestamps to format.
unit: strOne of None, 'auto', or a
datetime unit <arrays.dtypes.dateunits>.timezone: {'naive', 'UTC', 'local'} or tzinfoTimezone information to use when displaying the datetime. If 'UTC', end with a Z to indicate UTC time. If 'local', convert to the local timezone first, and suffix with a +-#### timezone offset. If a tzinfo object, then do as with 'local', but use the specified timezone.
casting: {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}Casting to allow when changing between datetime units.
Returns
str_arr: ndarrayAn array of strings the same shape as
arr.
Examples
import numpy as np from zoneinfo import ZoneInfo d = np.arange('2002-10-27T04:30', 4*60, 60, dtype='M8[m]') dSetting the timezone to UTC shows the same information, but with a Z suffix
np.datetime_as_string(d, timezone='UTC')
Note that we picked datetimes that cross a DST boundary. Passing in a
``ZoneInfo`` object will print the appropriate offset
np.datetime_as_string(d, timezone=ZoneInfo('US/Eastern'))
Passing in a unit will change the precision
np.datetime_as_string(d, unit='h') np.datetime_as_string(d, unit='s')'casting' can be used to specify whether precision can be changed
np.datetime_as_string(d, unit='h', casting='safe')
Aliases
-
numpy._core._multiarray_umath.datetime_as_string