-2

首先,我不太清楚它的核心语言是什么。我遵循了一个教程

我的代码如下所示:

{
    "type": "dateRange",
    "dateRange": "${time:extractStringFromDateTZ(time:now(), 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS')}/${time:extractStringFromDateTZ(time:now(), 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS')}"
}

这给了我以下信息:

{
    "type": "dateRange",
    "dateRange": "2019-04-01T00:00:00.000/2019-04-01T00:00:00.000"
}

我想要做的是从第一次约会中抽出 1 小时。这是我尝试过的:

前:

${time:extractStringFromDateTZ(time:now(), 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS')}

后:

${time:millisecondsToDateTime(time:dateTimeToMilliseconds(time:now()) - (3600), 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS')}

虽然这似乎是有效的代码,但它说它是无效的。请有人可以帮助我了解如何将“之前”代码修改为从现在开始的 1 小时。

4

2 回答 2

2

首先,正如您帖子的评论中提到的,1h 是 3600000 毫秒

然后,我从未使用过StreamSets但查看文档

the signature of the method you try to use is time:dateTimeToMilliseconds(<Date object>) and it returns a Long Its description is:

Converts a Date object to an epoch or UNIX time in milliseconds.

So you can't call it with these parameters , 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS'

This might be the valid syntax it is expecting:

${time:millisecondsToDateTime(time:dateTimeToMilliseconds(time:now()) - (3600000))}

You should be using other functions if you want to use a time zone:

time:millisecondsToDateTime(<long>) returns a Date object and time:extractStringFromDateTZ(<Date object>, <time zone>, <format string>) returns a String

Can't you chain them like this?

${time:extractStringFromDateTZ(
    time:millisecondsToDateTime(time:dateTimeToMilliseconds(time:now()) - 3600000), 
    'UTC', 
    'yyyy-MM-dd\'T\'HH:mm:ss.SSS')}
于 2019-06-05T13:58:47.140 回答
1

你可以这样尝试:

以毫秒为单位转换您的日期,然后 ( dateMilliseconds - 3600000) 结果需要转换为日期。

于 2019-06-05T13:46:23.177 回答