1
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 3 years have passed since last update.

SimpleDateFormatでUTCのISO形式日時文字列を出力するんだあ

Posted at

## 諸元

ニフクラのmBaaSに移行することになって、RestAPIのリクエストで渡す日時がUTCのISO形式だったのでなんとかしたかった。

2021-06-13T12:34:56.789Z ← 現在日時をこういう形式の文字列にしたい。

## やりかた

Calendarを使うてもあるけど、簡単なのはこっちか。

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String iWant = sdf.format(new Date());

"T"とか"Z"はシングルクォートで囲まないと

## ちなみに

ZonedDateTimeDateTimeFormatter使えっていう話はいったん置いておきます:)
うっかり他コンポーネントとのインターフェースをDateでやっちゃったんだあ:0

1
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
1
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?