0

在我的AppSync映射请求模板中,我需要在当前日期中添加或减去天。

我能找到的只是格式化和解析时间助手:$util.time 中的时间助手

#set( $todayString = $util.time.nowISO8601())

todayString 就像:2019-08-23T09:00:00.000Z 但我需要设置新变量,表示同一时间,但当前日期前一天或后一天,格式相同。

是否有可能只使用 vtl - 我的 DynamoDB 数据源的映射请求模板?

4

1 回答 1

1

我通过使用纪元时间工具找到了解决方案。由于它返回 long,我们可以像在这个示例中一样操作日期,然后使用现有的 time helper 将其转换回 ISO8601,它接受 long 值并返回进一步需要的格式化。

#set( $currentTimeEpoch = $util.time.nowEpochMilliSeconds())
#set( $fromStartEpoch = $currentTimeEpoch + (1000 * 60 * 60 * 24))
#set( $currentTime = $util.time.epochMilliSecondsToISO8601($currentTimeEpoch))
#set( $fromStart = $util.time.epochMilliSecondsToISO8601($fromStartEpoch))
于 2019-08-27T09:01:50.610 回答