08. Display the current time in various time zones around the world

Опубликовано: 07 Август 2026
на канале: Aljazari Foundation
24
0

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.TimeZone

// Get the current date and time in the default time zone
def currentDateTime = ZonedDateTime.now()

// List of time zones
def timeZones = TimeZone.getAvailableIDs()


// Format and print the current time in different time zones
timeZones.each { timeZoneId -(ganti dengan greater-than symbol)
def timeZone = TimeZone.getTimeZone(timeZoneId)
def zonedDateTime = currentDateTime.withZoneSameInstant(timeZone.toZoneId())
def formattedTime = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
println("Time in $timeZoneId: $formattedTime")

// Put the formatted time into JMeterVariables with a dynamic key
vars.put("formattedTime_${timeZoneId.replaceAll('[^a-zA-Z0-9]', '_')}", formattedTime)

}

tags : #dateandtime #jmeter #generator