当前位置:网站首页>postman生成时间戳,未来时间戳
postman生成时间戳,未来时间戳
2022-07-07 13:24:00 【Test-超哥】
支持获取:当前时间戳、未来时间戳、指定时间戳、当前年月日、未来年月日
- 获取当前时间戳
//获取当前时间戳
let timestamp = (new Date()).getTime().toString();
//控制台输出时间戳
console.log("当前时间戳:",timestamp)
//把startDate 设置时间戳为环境变量
pm.environment.set("startDate", timestamp);
演示:
- 指定日期,生成时间戳
//制定日期时间戳
var data_f = new Date(2022,7.05);
var appoint = data_f .getTime()
console.log("指定日期时间戳:",appoint)
pm.environment.set("expiration", appoint);
演示:
- 获取未来时间戳
// 获取当前时间格式为年月日
var date = new Date();
// 设置当前时间为3天后
date.setDate(date.getDate() + 3)
// 查看修改是否成功
console.log(date)
// 把修改后的时候,转换为时间戳
var toTimes = date.getTime()
// 查看时间戳
console.log(toTimes)
// 把 toTimes 设置为 expirationDate 环境变量
pm.environment.set("expirationDate", toTimes);
演示:
- 获取未来时间戳 之 “沙雕方法”:
//未来时间戳
let appoint = new Date().getTime();
// 三天总毫秒=259200000
appoint=appoint+259200000
console.log('72时的时间戳', appoint)
pm.environment.set("expirationDate", appoint);
演示:
- 获取:年月日 (YYYYMMDDHHmmss)
// 引用第三方库 :moment 等同于 import moment from 'moment'
var moment = require('moment');
// 调用 moment()方法获取当前时间,并进行格式化,用变量 currentRime 接收
var currentTime = moment().format(" YYYYMMDDHHmmss");
// 打印当前时间的值到控制台
console.log("当前时间是:", currentTime);
// 放到环境变量里
pm.environment.set("beginTime", currentTime);
演示:
- 获取未来时间:10分钟后的年月日
// 引用第三方库 :moment 等同于 import moment from 'moment'
var moment = require('moment');
// 未来时间,比如:当前时间的10分钟后,精确到秒
var beginTime = moment().add(10,"m").format(" YYYYMMDDHHmmss");
// 开始时间,当前时间的1小时后,精确到秒
var endTime = moment().add(1,"H").format(" YYYYMMDDHHmmss");
console.log("10秒后时间:", beginTime);
console.log("1小时后时间:", endTime);
演示:
- 年月日格式: 2022-07-04T11:27:15
// 72小时后的年月日时间
var moment = require('moment');
var YTD = moment().add(72,"H").format(" YYYY-MM-DDTHH:mm:ss");
console.log("72时后的年月日时间:",YTD);
// 设置为变量
pm.environment.set("tokenExpirationTime", YTD);
演示:
- 生成当前时间,类型为:“2022-07-01T05:18:17.580Z”
var a = new Date()
console.log("当前时间:",a)
演示:
- 生成后三天时间
var a = new Date()
a.setDate(4)
console.log("未来时间:",a)
演示:
边栏推荐
- [quick start of Digital IC Verification] 26. Ahb-sramc of SystemVerilog project practice (6) (basic points of APB protocol)
- [make a boat diary] [shapr3d STL format to gcode]
- MongoDB数据库基础知识整理
- Ctfshow, information collection: web13
- [deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
- 【数字IC验证快速入门】18、SystemVerilog学习之基本语法5(并发线程...内含实践练习)
- Ctfshow, information collection: web10
- The rebound problem of using Scrollview in cocos Creator
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- 什麼是數據泄露
猜你喜欢
【目标检测】YOLOv5跑通VOC2007数据集
Ctfshow, information collection: web9
[follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code
Stream learning notes
Ctfshow, information collection: web6
2022年5月互联网医疗领域月度观察
Typescript release 4.8 beta
Configure mongodb database in window environment
Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)
Getting started with webgl (1)
随机推荐
Window环境下配置Mongodb数据库
【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例
Monthly observation of internet medical field in May 2022
什么是pv和uv? pv、uv
连接ftp服务器教程
Basic knowledge sorting of mongodb database
There is a cow, which gives birth to a heifer at the beginning of each year. Each heifer has a heifer at the beginning of each year since the fourth year. Please program how many cows are there in the
Detailed explanation of Cocos creator 2.4.0 rendering process
【深度学习】图像超分实验:SRCNN/FSRCNN
Getting started with webgl (2)
HPDC smart base Talent Development Summit essay
Jacobo code coverage
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
如何在opensea批量发布NFT(Rinkeby测试网)
[make a boat diary] [shapr3d STL format to gcode]
How to deploy the super signature distribution platform system?
What are the safest securities trading apps
Mathematical modeling -- what is mathematical modeling
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)