如何将此日期格式 Thu Dec 01 00:00:00 GMT + 05:30 2016 解析为正常日期,月份和年份格式。
前:
String day = "Thu",
String month= "Dec",
String year= "2016"
答案 0 :(得分:1)
String input = "Thu Dec 01 00:00:00 GMT+05:30 2016";
SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Date date = parser.parse(input);
您可以从日期获得所需的数据。或者你要求:
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");
String dayOfWeek = dateFormat.format(date);//Thu
dateFormat = new SimpleDateFormat("MMM");
String month = dateFormat.format(date);//Dec
dateFormat = new SimpleDateFormat("yyyy");
String year = dateFormat.format(date);//2016
答案 1 :(得分:0)
试试这个:
String strDate = "";
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date= parser.parse(dateFromDB);
String dayOfTheWeek = (String) android.text.format.DateFormat.format("EEEE", date);
String stringMonth = (String) android.text.format.DateFormat.format("MMM", date);
String intMonth = (String) android.text.format.DateFormat.format("MM", date);
String year = (String) android.text.format.DateFormat.format("yyyy", date);
String day = (String) android.text.format.DateFormat.format("dd", date);
还要查看以下链接: Android date parsing (Extracting month and year )
Get Value Of Day Month form Date Object in Android?
How to get the day, year, hours, min Individually from date format "yyyy-MM-dd'T'HH:mm:ss.SSSZ"?