惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
博客园_首页
博客园 - 【当耐特】
V
Visual Studio Blog
博客园 - 叶小钗
月光博客
月光博客
美团技术团队
J
Java Code Geeks
小众软件
小众软件
Y
Y Combinator Blog
博客园 - Franky
Martin Fowler
Martin Fowler
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG

博客园 - 520_1351

使用Notepad++的快捷键运行Python时-报错-The security information for shortcuts.xml is missing in config.xml Powerautomate-控制Edge-浏览器-报错-Failed to assume control of Microsoft Edge (communication with Power Automate web extension failed) 关于-密码学算法中-类似-编程函数pow(3, 13, 7)的计算-快速幂算法结合模运算(Exponentiation by Squaring with Modular Reduction) 关于AWS-EC2-串口登录的-IAM权限-Policy-策略 关于使用 javascript 脚本语言中的 location.reload() 刷新当前页面 关于Bash - Shell脚本中的索引数组(Indexed Array) 关于Linux系统中-使用passwd对用户密码的锁定与解锁 关于 Redhat - 9 - 补丁升级后-旧版本内核相关的软件包卸载 关于 Redhat - 9 下 postfix 的安装配置 与 mail 命令发送邮件 关于 Amazon Linux 2023 (AL2023) 默认情况下确实没有 /var/log/secure 文件的解决方法 关于-HTML-内容-元素定位- CSS Selector 与 XPath 的说明及区别 关于Microsoft Power Automate-操作-Microsoft Access 数据库-【运行Access查询】 关于 Javascript 中 console.log("xxxx")-及console-对象其他常用的方法 关于Provider=Microsoft.ACE.OLEDB.12.0 与 Provider=Microsoft.ACE.OLEDB.16.0 的区别 通过Powershell-脚本-将指定的日期-转换成年周-格式-周数宽度为2 关于Windows-操作系统中-对带日期-或-数字-的文件目录-按名称排序的规则 关于Microsoft Power Automate-元素的定位-自定义写法去定位时-:nth-child 与 :eq 的区别 关于标准CSS伪类-以及在-Power Automate-等自动化工具中的使用 关于使用-Python-Selenium-模块-加载浏览器的扩展-的方法及注意事项-及只能加载一个扩展的解决方法 关于-根据-ISO8601-国际标准-计算一年中的周数-每年最少52周-每多53周 Redhat-9-中编译-EFS-客户端工具-即过程中-报错提示-warning: aws-lc-fips-sys@0.13.9: Building with: CMake-解决方法 关于Microsoft Power Automate-调用-Outlook-发送邮件-报错- A program is trying to access emal address information stored in Outlook 关于powershell中的-哈希表-Hashtable-类型-说明-类似于python中的字典 关于HTML中<font><b><i><s>等字体标签对-物理字体-逻辑字体的介绍及说明
关于 AWS Lambda 中的默认的时区-日期-时间-注意点
520_1351 · 2026-04-19 · via 博客园 - 520_1351

在 AWS Lambda 中,如果获取当前的日期与时间,默认得到的是UTC+0 或者 GMT 日期时间,并非中国的CST时间

可以通过如下代码看到效果

import boto3
from datetime import datetime, timedelta, timezone


def lambda_handler(event, context):
    
    # --- 计算北京时间 (UTC+8) ---
    now=datetime.now()
    utc_now = datetime.now(timezone.utc)
    beijing_now = utc_now + timedelta(hours=8)

    print("-----------",now)
    print("-----------",utc_now)
    print("-----------",beijing_now)

我是在 2026-04-16 的 上午11点19分执行的,结果如下:

Function Logs:
START RequestId: 69da4f44-bd0f-4d36-82ce-24d07745c202 Version: $LATEST
----------- 2026-04-16 03:19:05.812996
----------- 2026-04-16 03:19:05.813005+00:00
----------- 2026-04-16 11:19:05.813005+00:00
END RequestId: 69da4f44-bd0f-4d36-82ce-24d07745c202
REPORT RequestId: 69da4f44-bd0f-4d36-82ce-24d07745c202    Duration: 2.14 ms    Billed Duration: 334 ms    Memory Size: 128 MB    Max Memory Used: 69 MB    Init Duration: 331.80 ms

可以看到默认的日期时间与指定utc 0 时区datetime.now(timezone.utc) 的结果一样,CST时间+8小时就行

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/19891334