日期时间是aws胶水作业不采用本地时区,它使用UTC?

问题描述 投票:0回答:1

我正在 ap-south-1 区域运行 AWS Glue 作业。在这里,我使用了 python datetime 函数来加载我的审计列之一 (created_on)。当我尝试加载 datetime.now() 时,它采用 UTC 时区,而不是本地时区。如何解决这个问题,为什么glue 仍采用 UTC 时区,即使它托管在 ap-south-1 区域?

enter image description here

aws-glue
1个回答
0
投票

一种解决方案是直接在日期时间函数中提及区域,如下所示,我们可以定义这些方法来获取时间和日期。但这仍然没有回答为什么胶水作业 datetime.now() 不采用托管时区?

import pytz
from datetime import datetime

def get_current_timestamp():
    utc_now = datetime.utcnow()
    local_timezone = pytz.timezone('Asia/Kolkata')
    return utc_now.astimezone(local_timezone)

def get_current_date():
    utc_now = datetime.utcnow()
    local_timezone = pytz.timezone('Asia/Kolkata')
    return utc_now.astimezone(local_timezone).date()
© www.soinside.com 2019 - 2024. All rights reserved.