如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦
https://www.cnblogs.com/poloyy/p/13291704.html
作用
以给定格式返回日期,并添加指定的秒数,分钟,小时,天数
语法格式
${__timeShift(Format, Date to Shift, Value to Shift, Locale to use for format, Name of variable)}
参数讲解
字段 | 含义 | 是否必传 |
---|---|---|
Format |
| no |
Date to shift | 要转换的日期。如果省略,则日期设置为现在 | no |
Value to shift | 要移动的时间数 | no |
Locale to use for format | 语言环境的字符串格式,如:zh_CN、en_US | no |
Name of variable | 存储结果的变量名 | no |
Value to shift
重点讲下这个参数,它主要是表示要移动的秒、分、小时、天、月的数量,具体栗子如下
"PT20.345S" -- 增加 20.345 秒
"PT15M" -- 增加 15 分钟
"PT10H" -- 增加 10 消失
"P2D" -- 增加 2 天
"P2DT3H4M" -- 增加 2 天 3 小时 4 分钟
"PT-6H3M" -- 减少 6 小时,同时增加 3 分钟
"-PT6H3M" -- 减少 6小时 3 分钟
"-PT-6H+3M" -- 增加 6 小时,同时减少 3 分钟
- 如果是增减时、分、秒,前缀是 PT
- 如果是增减天,前缀是 P
小栗子
增加 20.345 秒
${__timeShift(yyyy/MM/dd HH:mm:ss, 2020/12/05 13:39:16, PT20.345S,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/05 13:39:36
![](https://i-blog.csdnimg.cn/blog_migrate/e8bd45a19e12eba9b4d728b783ef39d9.png)
增加 10 分钟、21 秒
${__timeShift(yyyy/MM/dd HH:mm:ss,2020/12/05 13:39:16,PT10m21s,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/05 13:49:37
![](https://i-blog.csdnimg.cn/blog_migrate/a1c6b9a12e47a7d983080b832ce77575.png)
减少 2 小时,增加 20 分钟、11 秒
${__timeShift(yyyy/MM/dd HH:mm:ss,2020/12/05 13:39:16,PT-2h20m11s,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/05 11:59:27
![](https://i-blog.csdnimg.cn/blog_migrate/d08e76b069b817e34ffbd19f4b44a5dc.png)
减少 2 小时、2 分钟、2 秒
${__timeShift(yyyy/MM/dd HH:mm:ss,2020/12/05 13:39:16,-PT2h2m2s,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/05 11:37:14
![](https://i-blog.csdnimg.cn/blog_migrate/88faefc9760b06db691a5ea66db7ec26.png)
增加 2 天数、3 小时、4 秒
${__timeShift(yyyy/MM/dd HH:mm:ss,2020/12/05 13:39:16,P2DT3H4S,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/07 16:39:20
![](https://i-blog.csdnimg.cn/blog_migrate/77b8fe0b1b8871b9df7c1c691584d976.png)
减少 2 天数,增加 2 小时、4 分钟,减少 2 s
${__timeShift(yyyy/MM/dd HH:mm:ss,2020/12/05 13:39:16,P-2DT+2h4m-2s,,)}
- 当前时间:2020/12/05 13:39:16
- 返回结果:2020/12/03 15:43:14
![](https://i-blog.csdnimg.cn/blog_migrate/54c420243343c1f395ae1d2fdbbbde14.png)