Note that I got stuck when processing Response from API in Jmeter.
Fri Apr 4 00:00:00 UTC+0900 1902
To format such a date string to Date
new SimpleDateFormat("EEE MMM dd HH:mm:ss zZ yyyy", Locale.ENGLISH);
This.
Official SimpleDateFormat documentation
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00 Z Time zone RFC 822 time zone -0800
I wrote, but I couldn't think of a combination. The whole code is below.
import java.text.SimpleDateFormat;
String date = "Fri Apr 4 00:00:00 UTC+0900 1902";
// Original format to convert from
SimpleDateFormat formatFrom = new SimpleDateFormat("EEE MMM dd HH:mm:ss zZ yyyy", Locale.ENGLISH);
// Target format to convert to
SimpleDateFormat formatTo = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss zZ", Locale.ENGLISH);
// Parse original string, using original format
Date formatDate = formatFrom.parse(date);
// Convert to a target format
String newDate = formatTo.format(formatDate);
System.out.println(newDate);
reference: https://stackoverflow.com/questions/47165086/how-to-convert-datetime-in-jmeter-using-beanshell-sampler
Recommended Posts