gpt4 book ai didi

python - 如何将 execution_date 作为纪元时间?

转载 作者:行者123 更新时间:2023-12-05 01:40:50 25 4
gpt4 key购买 nike

在常规的 python 代码中我可以这样做:

import time
int(time.time())

这给了我作为纪元的时间。我希望能够使用 Airflow 宏执行此操作:execution_date

这是我尝试过的:

"{{  strptime(execution_date.strftime('%Y-%m-%d %H:%M:%S'), '%d.%m.%Y %H:%M:%S') }}"

但这给出了:

jinja2.exceptions.UndefinedError: 'strptime' is undefined

我正在运行 Airflow 1.9 和 Python 2.7

最佳答案

从 Airflow 1.10 开始,Airflow 使用 Pendulum 作为日期时间,它具有返回纪元的属性 timestamp()int_timestampfloat_timestamp

所以,你可以这样做:

{{ execution_date.int_timestamp }}

文档:https://pendulum.eustace.io/docs/#attributes-and-properties

其他选项是:

{{ execution_date.strftime('%s') }} # Also Python 2
{{ execution_date.timestamp() }} # Python >=3.3

关于python - 如何将 execution_date 作为纪元时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55720663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com