【发布时间】:2016-08-05 09:34:37
【问题描述】:
我的日期是“2016-08-05 14:46:53 +05:30”,并且 我使用的日期和时间格式是“yyyy-MM-DD HH:mm:ss +05:30” 问题是,当我解析这个日期时,我得到输出 "Tue Jan 05 14:46:53 GMT+05:30 2016" 我不明白问题出在哪里。 我正在使用的代码发布在下面。
public class DateFormater {
private static String DATE_TIME_FORMAT = "yyyy-MM-DD HH:mm:ss +05:30";
private static String TAG = DateFormater.class.getSimpleName();
public static Date getDate(String s) {
//Input s = 2016-08-05 14:46:53 +05:30
Date date = null;
try {
SimpleDateFormat dateFormat=new SimpleDateFormat(DATE_TIME_FORMAT);
date=dateFormat.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static String getCurrentDateString(Date date) {
DateFormat dateFormat=SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
Log.i(TAG, "getCurrentDateString: "+dateFormat.format(date));
return dateFormat.format(date);
}
public static String getCurrentTimeString(Date date) {
DateFormat dateFormat=SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
return dateFormat.format(date);//Tue Jan 05 14:46:53 GMT+05:30 2016
}}
【问题讨论】:
-
DD不是您要查找的令牌,请使用dd。 -
知道了,伙计。谢谢
标签: java date simpledateformat