Java/Android:转换日期,如;2014-11-26T15:58:54.259+;01:00“;到当前区域设置

Java/Android:转换日期,如;2014-11-26T15:58:54.259+;01:00“;到当前区域设置,java,android,date,Java,Android,Date,我从我的网站上得到了一个类似“2014-11-26T15:58:54.259+01:00”的日期 我想将其转换为设备上配置的语言环境。 以下是我迄今为止所做的工作: String string = currentDatasetBundle.dataset.created_at; SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",Locale.GERMANY); SimpleDateForma

我从我的网站上得到了一个类似“2014-11-26T15:58:54.259+01:00”的日期 我想将其转换为设备上配置的语言环境。 以下是我迄今为止所做的工作:

String string = currentDatasetBundle.dataset.created_at;
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",Locale.GERMANY);
SimpleDateFormat outFormat = (SimpleDateFormat) android.text.format.DateFormat.getDateFormat(getContext());
Date date;

String output = null;
try {
    date = inFormat.parse(string);
    output = outFormat.format(date);
} catch (ParseException e) {
    e.printStackTrace();
}
dateLabel.setText(output);
一切正常,但时间不会显示在我的
输出
字符串中。 看起来像是2014年11月26日,但我想展示一下时间,比如2014年11月26日15:58:54? 我做错了什么?

您使用的是仅格式化日期的。附加到输出


完整代码:

String string = currentDatasetBundle.dataset.created_at;
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",Locale.GERMANY);
Date date;

String output = null;
try {
    date = inFormat.parse(string);
    output = android.text.format.DateFormat.getDateFormat(getContext()).format(date)
        + " " + android.text.format.DateFormat.getTimeFormat(getContext());
} catch (ParseException e) {
    e.printStackTrace();
}
dateLabel.setText(output);