gpt4 book ai didi

momentjs - Joi unix 时间戳设置最大值

转载 作者:行者123 更新时间:2023-12-04 21:07:51 24 4
gpt4 key购买 nike

我正在使用 Joi用于验证时间戳字段的包,但如何在其上设置 max() 值,我希望输入时间戳小于当前时间戳

var schema = Joi.object().keys({
t: Joi.date().timestamp('unix').max(moment().unix()),
})

但我得到的错误是:

child "t" fails because ["t" must be less than or equal to "Sun Jan 18 1970 07:35:17 GMT+0330 (IRST)"]



我确定 moment().unix()返回当前时间戳,但在这里它被转换为字符串。

最佳答案

看来max()min()函数可以做到这一点,但它们只有在以毫秒为单位指定阈值时才有效。

t: Joi.date().timestamp('unix')
.max(moment().unix() * 1000)
.min(moment().subtract('42', 'weeks').unix() * 1000),

关于momentjs - Joi unix 时间戳设置最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41459314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com