LoginSignup
1
1

More than 5 years have passed since last update.

AndroidでrailsのDateTimeをパースし、ローカルロケール時刻テキストに変換

Posted at

RailsのDateTimeをandroidローカル時間のテキストに変換するコード。
RailsでDateTimeとして保存している場合、そのまま出力した場合、"2015-06-30T13:00:50.000Z"のように出力される。

public final static String TIME_FORMAT = "yy/MM/dd HH:mm:ss";

//UTC標準時刻をローカル時間のテキストに変換する。
public String toLocalTime(String utcTime) {

    try {
        Time t = new Time();
        t.parse3339(utcTime);
        long msec = t.normalize(false);
        Date d = new Date( msec );
        SimpleDateFormat df = new SimpleDateFormat();

        return  df.format(d);
    } catch (TimeFormatException e) {
        return null;
    }
}
1
1
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
1