meteociel.utils.get_seconds

meteociel.utils.get_seconds(date: datetime, ref_string: str = '1970-01-01 01:00', ref_fmt: str = '%Y-%m-%d %H:%M')

Compute the elapsed seconds since a given reference time (by default epoch).

Parameters

datedatetime

Date up to which the number of elapsed seconds is to be calculated.

ref_stringstr, optionnal

By default: "1970-01-01 01:00" (epoch). The time to be used as reference for calculations.

ref_fmtstr, optionnal

By default: "%Y-%m-%d %H:%M". The format to be used to read ref_string. For more information on format codes, please see the datetime documentation

Returns

outint

The number of elapsed seconds between the reference and the given time.

Exemples

This exemple computes the number of elapsed seconds between epoch and 2022/08/18 00h GMT:

>>> from datetime import datetime
>>> from meteociel import utils
>>> utils.get_seconds(datetime.strptime("2022-08-18 00", "%Y-%m-%d %H"))
1660777200