# -*- coding: utf-8 -*- import arrow TIME_FMT = "YYYYMMDDHHmmss" def get_time_str( delta: int = 0, flag: str = "now", fmt: str | None = TIME_FMT ) -> str: """ Return a Beijing time strings. :param delta: time delta(seconds) :param flag: :param fmt: time string's format :return: a '%Y%m%d%H%M%S' format strings """ utc = arrow.utcnow() local = utc.to("Asia/Shanghai") if flag == "ago": delta = -delta t = local.shift(seconds=delta) elif flag == "later": t = local.shift(seconds=delta) else: t = local time_str = t.format(fmt) return time_str def get_quarter_minutes(time_str: str) -> str: temp = arrow.get(time_str, TIME_FMT).timestamp() // (15 * 60) * (15 * 60) return arrow.get(temp).time().strftime("%H%M%S")