You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从日期时间变量中获取星期几的数字?

从JMeter时间变量中获取星期几数字的实现方法

完全可行,你可以通过以下两种方式实现需求:

  • 直接用__timeShift函数生成星期几数字
    若无需单独保留完整日期时间字符串,可让__timeShift直接输出星期几的数字格式。注意两种不同的星期计数规则:

    • ISO标准规则(1=周一,7=周日):使用格式符u
      ${__timeShift(u,,PT2M,,)}
      
    • JMeter默认规则(1=周日,2=周一…7=周六):使用格式符E
      ${__timeShift(E,,PT2M,,)}
      
  • 从已有的日期时间变量提取星期几
    如果已经生成了类似StartTime的日期时间变量(格式为yyyy-MM-dd HH:mm),可通过__groovy脚本解析提取:

    • 获取ISO标准星期几:
      ${__groovy(DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm').parse(vars.get('StartTime')).getDayOfWeek().getValue(),)}
      
    • 获取JMeter默认规则的星期几:
      ${__groovy(Calendar.getInstance().with{setTime(DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm').parse(vars.get('StartTime'))); get(Calendar.DAY_OF_WEEK)},)}
      

内容的提问来源于stack exchange,提问作者Madhu Manohar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 13:45:02