【发布时间】:2017-07-26 18:16:35
【问题描述】:
我得到一个 JSON "dt_txt":"2017-07-26 21:00:00" 作为日期和时间,但我只想要“dd MMM, yyyy”格式的日期,即“2017 年 7 月 26 日”。
【问题讨论】:
标签: android
我得到一个 JSON "dt_txt":"2017-07-26 21:00:00" 作为日期和时间,但我只想要“dd MMM, yyyy”格式的日期,即“2017 年 7 月 26 日”。
【问题讨论】:
标签: android
你需要使用 SimpleDateFormat
String dt_txt = "2017-07-26 21:00:00";
try {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = fmt.parse(dt_txt);
SimpleDateFormat fmtOut = new SimpleDateFormat("dd MMM, yyyy HH:mm:ss");
String newFormat = fmtOut.format(date);
Log.i("kapil", " " + newFormat);
}catch (Exception e){
e.printStackTrace();
}
【讨论】: