Jmeter 常用函数(32)- 详解 __timeShift

如果你想查看更多 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
  • DateTimeFormatter,日期格式
  • 不指定默认会返回毫秒数。建议格式: yyyy/MM/dd HH:mm:ss 
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"  -- 增加 23 小时 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

 

增加 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

 

减少 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

 

减少 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

 

增加 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

 

减少 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

 

posted @ 2020-12-05 16:54  小菠萝测试笔记  阅读(1760)  评论(0编辑  收藏  举报