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

Azure Logic Apps中如何将特定格式时间戳转换为UTC时间

解决Azure Logic Apps中/Date(时间戳)/格式转UTC时间的问题

原表达式出现无效日期的核心原因是依赖固定字符串长度提取时间戳,一旦字段格式有细微变化(比如带时区偏移),就会导致提取的数字错误,进而引发日期转换失败。以下是修正后的可靠方案:

修正后的表达式

if(
    and(
        not(empty(items('For_each')?['student'])),
        not(empty(items('For_each')?['student']['results'])),
        greater(length(items('For_each')?['student']['results']), 0),
        not(empty(items('For_each')?['student']['results']?[0]?['birthDay']))
    ),
    formatDateTime(
        addToTime(
            '1970-01-01T00:00:00Z',
            div(
                int(
                    split(
                        split(items('For_each')?['student']['results']?[0]?['birthDay'], '(')[1],
                        ')'
                    )[0]
                ),
                1000
            ),
            'Second'
        ),
        'yyyy-MM-ddTHH:mm:ssZ'
    ),
    null
)

关键改进点

  • 替换固定长度提取为split分割:通过两次split操作直接提取括号()之间的数字部分,无需计算字符长度,适配/Date(1234567890000)/或带时区的/Date(1234567890000+0800)/等多种格式。
  • 确保时间戳纯数字转换:先拆分出纯数字字符串再转整数,避免因提取到非数字字符导致的int转换失败。

测试步骤

  1. 在Logic Apps中添加一个单独的Compose动作,输入split(items('For_each')?['student']['results']?[0]?['birthDay'], '(')[1],验证拆分后是否得到包含时间戳和右括号的字符串。
  2. 再添加一个Compose动作,输入split(上一步输出, ')')[0],确认得到纯数字时间戳。
  3. 将验证后的拆分逻辑替换原表达式中的substring部分,即可正常转换。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 19:13:11