腾讯云函数计算时间戳与时区说明

腾讯云函数计算函数内的时间戳为Unix时间戳(Unix timestamp),时间为UTC世界标准时间。如果您需要在函数内打印格式化时间,需要指定时区,例如 "Asia/Shanghai"。以下提供nodejs和python两种语言的示例代码,仅供参考:

nodejs相关示例:

exports.handler = (event, context, callback) => { let d = new Date(); console.log(d.toUTCString()) console.log(d.toLocaleString("en-US", {timeZone: "Asia/Shanghai"})) console.log(d.toISOString()) callback(null, "Hello world!");};

python相关示例:

# -*- coding: utf-8 -*-from datetime import datetime, timedelta, timezonedef handler(event, context): utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc) print("utc datetime : ", utc_dt) bj_dt = utc_dt.astimezone(timezone(timedelta(hours=8))) print("bj datetime : ", bj_dt) return "Hello World"

标签