Time Conversions

Convert from unix time to a string

pyspedas.time_string(float_time=None, fmt=None)

Transform a list of float daytime values to a list of strings.

Parameters
  • float_time (float/list of floats, optional) – Input time. The default is None, which returns the time now.

  • fmt (str, optional) – Time format. The default is None, which uses ‘%Y-%m-%d %H:%M:%S.%f’.

Returns

Datetimes as string.

Return type

list of str

Example

from pyspedas import time_string
time_string(1444953600.0)
'2015-10-16 00:00:00.000000'

Convert from a string to unix time

pyspedas.time_double(str_time=None)

Transform a list of datetimes from string to decimal.

Same as time_float.

Parameters

str_time (str/list of str, optional) – Input times. The default is None.

Returns

Output times as floats.

Return type

list of float

Example

from pyspedas import time_double
time_double('2015-10-16/14:00')
1445004000.0

Convert from a string or unix time to a datetime object

pyspedas.time_datetime(time=None, tz=None)

Find python datetime.

Transform a list of float daytime values to a list of pythonic

‘datetime.datetime’ values.

Parameters

time (float/list of floats or str/list of str, optional) – Input time. The default is None, which returns the time now.

Returns

Datetimes as datetime.datetime.

Return type

list of datetime.datetime

Example

from pyspedas import time_datetime
time_datetime('2015-10-16/14:00')
datetime.datetime(2015, 10, 16, 14, 0, tzinfo=datetime.timezone.utc)