当前位置:网站首页>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)
演示:
边栏推荐
- MySQL bit类型解析
- 一个需求温习到的所有知识,h5的表单被键盘遮挡,事件代理,事件委托
- Briefly describe the working principle of kept
- MongoD管理数据库的方法介绍
- 【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
- Oracle control file loss recovery archive mode method
- [deep learning] image hyperspectral experiment: srcnn/fsrcnn
- Ctfshow, information collection: Web3
- Gd32 F3 pin mapping problem SW interface cannot be burned
- Keil5 does not support online simulation of STM32 F0 series
猜你喜欢
Ctfshow, information collection: web8
众昂矿业:萤石继续引领新能源市场增长
Ctfshow, information collection: web14
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
Win10 or win11 taskbar, automatically hidden and transparent
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
#HPDC智能基座人才发展峰会随笔
[quick start of Digital IC Verification] 22. Ahb-sramc of SystemVerilog project practice (2) (Introduction to AMBA bus)
【數字IC驗證快速入門】20、SystemVerilog學習之基本語法7(覆蓋率驅動...內含實踐練習)
【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)
随机推荐
How to release NFT in batches in opensea (rinkeby test network)
Starting from 1.5, build a microservice framework link tracking traceid
MySQL bit类型解析
Basic knowledge sorting of mongodb database
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
Getting started with webgl (1)
知否|两大风控最重要指标与客群好坏的关系分析
jacoco代码覆盖率
[markdown grammar advanced] make your blog more exciting (IV: set font style and color comparison table)
什麼是數據泄露
The download button and debug button in keil are grayed out
大表delete删数据导致数据库异常解决
Bye, Dachang! I'm going to the factory today
2.Golang基础知识
连接ftp服务器教程
Qu'est - ce qu'une violation de données
Ctfshow, information collection: web5
【數字IC驗證快速入門】20、SystemVerilog學習之基本語法7(覆蓋率驅動...內含實踐練習)
With 8 modules and 40 thinking models, you can break the shackles of thinking and meet the thinking needs of different stages and scenes of your work. Collect it quickly and learn it slowly
[quick start for Digital IC Validation] 26. Ahb - sramc (6) for system verilog project practice (Basic Points of APB Protocol)