0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SimpleDateFormatでフォーマットする際のタイムゾーンの扱いでつまった

Posted at

JmeterでAPIからのResponseを処理するときに詰まったのでメモ。

Fri Apr 4 00:00:00 UTC+0900 1902

このような日付の文字列をDateにフォーマットするには

new SimpleDateFormat("EEE MMM dd HH:mm:ss zZ yyyy", Locale.ENGLISH);

これです。

公式のSimpleDateFormatのドキュメントには、

z タイムゾーン 一般的なタイムゾーン Pacific Standard Time; PST; GMT-08:00
Z タイムゾーン RFC 822タイムゾーン -0800

と書いていましたが、組み合わせが思いつかずでした。
全体のコードは下記になります。

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);

参考:
https://stackoverflow.com/questions/47165086/how-to-convert-datetime-in-jmeter-using-beanshell-sampler

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?