Json 邮递员:UTC检查器
我一直在寻找最好的解决方案:Json 邮递员:UTC检查器,json,postman,Json,Postman,我一直在寻找最好的解决方案: { startDate: *insert UTC here* } 在我的邮递员测试中,我需要验证我的startDate是否为UTC格式。这是一种使用正则表达式检查日期格式的糟糕方法,我不建议这样做,但它会起作用: 这是针对Windows本机客户端运行的,如果您仍然使用chrome扩展,它将无法工作,因为它没有pm.*API 在测试中,您可以将我使用的demodateFormat变量替换为注释中示例中的jsonData.data.startDate。使用Java
{
startDate: *insert UTC here*
}
在我的邮递员测试中,我需要验证我的
startDate
是否为UTC格式。这是一种使用正则表达式检查日期格式的糟糕方法,我不建议这样做,但它会起作用:
这是针对Windows本机客户端运行的,如果您仍然使用chrome扩展,它将无法工作,因为它没有pm.*
API
在测试中,您可以将我使用的demo
dateFormat
变量替换为注释中示例中的jsonData.data.startDate
。使用Javascript日期对象验证日期。
只有当它的格式很好并且包含真实日期时,它才会通过
stringWithISODate = '2020-10-23T00:00:00.000Z';
thedate = new Date(stringWithISODate);
theDateString = thedate.toISOString();
if (stringWithISODate == theDateString) {
console.log('yea it is ISO');
}
stringWithUTCDate = 'Fri, 23 Oct 2020 00:00:00 GMT';
thedate = new Date(stringWithUTCDate);
theDateString = thedate.toUTCString();
if (stringWithUTCDate == theDateString) {
console.log('yea it is UTC');
}
UTC格式是什么意思?到目前为止你试过什么?这在邮递员身上是什么样子?实际响应数据结构是什么?创建一个缺少细节的问题并不是在寻找解决方案,而是在等待解决方案。首先,我尝试使用字符串函数includes,但postman不支持它。UTC格式2018-02-28T00:00:00.000Z类似于此,测试[“相同开始日期”]=jsonData.data.startDate.includes(开始日期值);第一次尝试:使用includes“postman不支持”…你是什么意思?邮递员会把你告诉它的任何东西寄给你。背景是什么?你犯了什么错误?编辑问题,包括正确的代码、错误消息和对您实际试图实现的目标的清晰解释。谢谢。直接发布一个包含使用正则表达式匹配特定字符串格式的答案是很简单的,但如果这不是您需要的,那么它是可怕的,毫无意义的。没有更多的细节,任何人都很难提供帮助。
stringWithISODate = '2020-10-23T00:00:00.000Z';
thedate = new Date(stringWithISODate);
theDateString = thedate.toISOString();
if (stringWithISODate == theDateString) {
console.log('yea it is ISO');
}
stringWithUTCDate = 'Fri, 23 Oct 2020 00:00:00 GMT';
thedate = new Date(stringWithUTCDate);
theDateString = thedate.toUTCString();
if (stringWithUTCDate == theDateString) {
console.log('yea it is UTC');
}