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

JMeter中将当前系统时间转换为GMT及EPOCH时间的实现方案咨询

JMeter IST时间转GMT、EPOCH时间实现方案

首先明确IST为印度标准时间,对应时区ID为Asia/Kolkata,偏移为UTC+5:30,以下是两种可行实现方法:

方法1:内置函数实现(无需编码,适合简单场景)

  • IST转GMT时间(格式dd/MM/yyyy HH:mm:ss)
    直接调用JMeter自带的__timeShift函数,指定输出时区为GMT即可:
    ${__timeShift(dd/MM/yyyy HH:mm:ss,,P0D,GMT,gmt_time)}
    
    执行后生成的GMT时间会自动存入gmt_time变量,后续可直接引用。
  • IST转EPOCH时间
    EPOCH时间本身以UTC为基准,无需额外做时区转换,直接调用__time函数即可:
    • 13位毫秒级EPOCH:${__time(,epoch_milli)}
    • 10位秒级EPOCH:${__jexl3(${__time(,)} / 1000,epoch_second)}

方法2:JSR223 Groovy脚本实现(灵活度高,适合复杂逻辑)

推荐使用Groovy语言,性能优于BeanShell,操作步骤如下:

  1. 按需添加JSR223预处理/后处理器到对应请求下
  2. 填入以下脚本:
// 指定IST时区
def istZone = TimeZone.getTimeZone("Asia/Kolkata")
def currentIstTime = Calendar.getInstance(istZone).getTime()

// 转换为指定格式GMT时间
def gmtSdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")
gmtSdf.setTimeZone(TimeZone.getTimeZone("GMT"))
vars.put("gmt_time", gmtSdf.format(currentIstTime))

// 转换为EPOCH时间
def epochMilli = currentIstTime.getTime()
def epochSecond = (epochMilli / 1000) as long
vars.put("epoch_milli", epochMilli.toString())
vars.put("epoch_second", epochSecond.toString())

注意:格式符中大写MM代表月份,小写mm代表分钟,切勿混淆避免格式错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 08:15:03