bundles / numpy 2.4.3 / numpy / datetime_as_string
_ArrayFunctionDispatcher
numpy:datetime_as_string
Signature
def 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]') d✓
np.datetime_as_string(d, timezone='UTC')
✓np.datetime_as_string(d, timezone=ZoneInfo('US/Eastern'))
✓np.datetime_as_string(d, unit='h')
✓np.datetime_as_string(d, unit='s')
✗np.datetime_as_string(d, unit='h', casting='safe')
✗Aliases
-
numpy.datetime_as_string