postman - 如何在 Postman 中获取不同时区的当地时间?
问题描述
我想获取罗马时区的当地时间。在这里postman_sandbox_api_reference中没有找到关于如何在邮递员文档中使用时刻沙箱内置库的任何详细信息
到目前为止我尝试过的
var moment = require('moment');
console.log(moment().tz(environment.TimeZone).format());
它抛出的错误 - TypeError | moment(...).tz is not a function
又一次尝试——
var moment = require('moment-timezone');
console.log(moment().tz(environment.TimeZone).format());
它抛出的错误 -Error | Cannot find module 'moment-timezone'
我哪里错了?谁能指出我正确的方向。
谢谢
解决方案
Postman 只有moment
内置库,没有moment-timezone
.
如果您正在做的事情不是moment
文档的一部分,那么它将无法正常工作。
作为获取数据的一种解决方法,您可以使用简单的 3rd 方 API。
向此端点发出请求将为您提供一些您可以使用的时区数据。
http://worldtimeapi.org/api/timezone/Europe/Rome
这可以添加到pm.sendRequest()
中pre-request script
以获取您需要的数据并在另一个请求中使用它。
pm.sendRequest("http://worldtimeapi.org/api/timezone/Europe/Rome", function (err, res) {
pm.globals.set("localTimeRome", res.json().datetime);
});
推荐阅读
- java - 从内部连接发布到 Maven 中心
- buffer - AudioKit / AVAudioEngine 依次播放节点
- oracle - USERENV('SESSIONID') 和 USERENV('SID) 之间的区别?
- python - 如何在 R 中保存 logit 模型并在 Python 中导入?
- php - 从 PHP 中的数组中获取特定值
- xamarin.forms - Xamarin 表单集合视图额外填充
- java - 如何在截止日期调用 grpc blockstub 时管理应用程序崩溃
- angular - Angular httpClient - RXJS 用法
- python - 如何将参数传递给python中的映射器函数?
- php - 需要使用 WordPress 按钮触发 Linux 后端脚本