0
0

More than 3 years have passed since last update.

【Android】UTC(GMT) -> スマホのTimeZoneに応じた時刻表示 超個人的メモ

Posted at

盛大にハマった
二度とハマりたくない
とりあえずこれで動く

String utcDateString = "Wed, 11 May 1982 12:25:45 GMT";
SimpleDateFormat enDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
enDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date utcDate = null;
try {
    utcDate = enDateFormat.parse(utcDateString);
} catch (ParseException e) {

}

SimpleDateFormat localizedFormat = new SimpleDateFormat("MM-dd HH:mm", Locale.ENGLISH);
localizedFormat.setTimeZone(TimeZone.getDefault());
String localizedFormattedString = localizedFormat.format(utcDate);
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