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#
# 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#
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
This module extends the tools.timeconv with some functions implemented in pure python
- datetime_to_datestring(dt: datetime, fractionalSecondsDigits: int = 0, format: str = '%z__%d-%m-%Y__%H:%M:%S') str #
Converting python datetime objects to datestrings
- Parameters:
dt (datetime) – datetime to be converted
fractionalSecondsDigits (int, optional) – How many digits to use for the split seconds. Minimum is 0 (second resolution) Maximum is 6 (microsecond resolution), by default 0
format (_type_, optional) – %z__%d-%m-%Y__%H:%M:%S” see: https://m.cplusplus.com/reference/ctime/strftime/, https://themachinethatgoesping.readthedocs.io/en/latest/modules/tools/timeconv.html#format-string by default ‘%z__%d-%m-%Y__%H:%M:%S’
- Returns:
DateString that fits to the specified format
- Return type:
- datestring_to_datetime(datestring: str, format: str = '%z__%d-%m-%Y__%H:%M:%S') datetime #
Converting date strings to python datetime objects
- Parameters:
datestring (str) – DateString to be converted. Must fit format string.
format (_type_, optional) – %z__%d-%m-%Y__%H:%M:%S” see: https://m.cplusplus.com/reference/ctime/strftime/, https://themachinethatgoesping.readthedocs.io/en/latest/modules/tools/timeconv.html#format-string by default ‘%z__%d-%m-%Y__%H:%M:%S’
- Returns:
python datetime object
- Return type:
datetime
Functions (python extendet)#
# import this extended module
from themachinethatgoesping.tools import timeconv