timeconv

This modules provides functions to convert between a datestring format and unixtime timestamp (double). The unixtimestamp is defined in seconds since 1970 UTC time. The datestring object will also be UTC by default.

Example usage

https://mybinder.org/badge_logo.svg
# import this module
import time # default pyhon module
from themachinethatgoesping.tools import timeconv

unixtime   = time.time() # create a unixtimestamp in python
datestring = timeconv.unixtime_to_datestring(time.time()) # convert to datestring
print(datestring)

unixtime = timeconv.datestring_to_unixtime(datestring) # convert datestring to unixtimestamp
print(unixtime)

Format string

date_string format

Format

Meaning

%z:

zone (in hhmm (as hours/minuts east of utc)
z may only be at the beginning of the string!
If no z is given the string will be interpreted as utc 0

%d:

get_day as int dd

%m:

get_month as int mm

%b:

get_month as string bb

%Y:

get_year is int YYYY

%H:

hours as int HH

%M:

Minutes as int mm

%S:

Seconds as int SS

Functions (c++ module)

# import this module
from themachinethatgoesping.tools import timeconv

Convenient functions for converting time strings.

datestring_to_unixtime(unixtime: str, format: str = '%z__%d-%m-%Y__%H:%M:%S') float

Converting between date strings and unixtime stamps (ref 1970)

Parameter DateString::

DateString to be converted. Must fit format string.

Parameter format::

Format string to convert Date string. Default Format: “%z__%d-%m-%Y__%H:%M:%S” see https://m.cplusplus.com/reference/ctime/strftime/ * https://themac hinethatgoesping.readthedocs.io/en/latest/modules/tools/timeconv.h tml#format-string

Returns

unixtime as double (seconds since 01.01.1970)

unixtime_to_datestring(unixtime: float, fractionalSecondsDigits: int = 0, format: str = '%z__%d-%m-%Y__%H:%M:%S') str

Converting between date strings and unixtime stamps (ref 1970)

Parameter unixtime::

seconds since 01.01.1970 as double

Parameter fractionalSecondsDigits::

How many digits to use for the split seconds. Minimum is 0 (second resolution) Maximum is 6 (microsecond resolution)

Parameter format::

Format string to convert Date string. Default Format: “%z__%d-%m-%Y__%H:%M:%S” see: https://m.cplusplus.com/reference/ctime/strftime/ * https://themac hinethatgoesping.readthedocs.io/en/latest/modules/tools/timeconv.h tml#format-string

Returns

DateString that fits to the specified format

Functions (python extendet)

# import this extended module
from themachinethatgoesping.tools_ext import timeconv