You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Logic Apps中将Unix时间戳转换为hh:mm Am/Pm格式

在Logic Apps中将Unix时间戳字符串转换为'hh:mm Am/Pm'格式的实现方法

核心逻辑

先把Unix时间戳字符串转成数值,再转换为DateTime类型,最后通过格式化函数输出目标格式。

具体步骤

  1. 字符串转数值
    Unix时间戳一般以字符串形式存在,先用int()函数转为整数:

    int(triggerBody()?['unixTimestamp'])
    

    把triggerBody()?['unixTimestamp']替换成你实际的时间戳字段或变量。

  2. 数值转DateTime
    Logic Apps的timestamp()函数只接受毫秒级时间戳,如果你的时间戳是秒级,得乘以1000转换:

    • 秒级时间戳转DateTime:
      timestamp(mul(int(triggerBody()?['unixTimestamp']), 1000))
      
    • 毫秒级时间戳直接转换:
      timestamp(int(triggerBody()?['unixTimestamp']))
      
  3. 格式化输出目标格式
    用formatDateTime()函数,指定格式字符串'hh:mm tt'(tt对应Am/Pm标识):

    formatDateTime(timestamp(mul(int(triggerBody()?['unixTimestamp']), 1000)), 'hh:mm tt')
    

示例演示

假设输入的Unix时间戳字符串是'1620000000'(秒级),完整表达式为:

formatDateTime(timestamp(mul(int('1620000000'), 1000)), 'hh:mm tt')

最终输出结果为07:00 AM。

时区自定义

如果需要指定时区,可在formatDateTime里添加时区参数,比如指定UTC时区:

formatDateTime(timestamp(mul(int('1620000000'), 1000)), 'hh:mm tt', 'UTC')

支持的时区字符串包括'Asia/Shanghai'、'Europe/London'等。

内容的提问来源于stack exchange,提问作者Rajat Bajaj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 14:40:29