2015-12-23 49 views
0
deliverdate="Wed Dec 23 14:49:02 IST 2015 ";  
SimpleDateFormat fmt = new SimpleDateFormat("E MMM dd hh:mm:ss Z yyyy"); 
Date today = null; 
try { 
    today = (Date) fmt.parse(deliverdate); 
} catch (ParseException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

java.sql.Date dt = new java.sql.Date(today.getTime()); 
String finaltimedate = dt.toString(); 

轉換SQLDATETIME格式我正在轉換給定日期使用給定的代碼Sqlformat在android系統日期時間,但我得到錯誤的輸出finaltimedate:2015-12-23而我想這種格式23-12-2015 5:00 PM請告訴我哪裏做錯了,請建議我時間不是在android系統

+0

你想看到的地方? –

+0

如果你想要這種格式'「dd-MM-yyyy h:mm a」'你爲什麼要通過這個''E MMM dd hh:mm:ss Z yyyy「'?另外,我不認爲這個日期是有效的'「Wed Dec 23 14:49:02 IST 2015」' –

+0

如果在數據庫中,那麼只需要指定日期時間輸出。見[it](http://www.tutorialspoint.com/sqlite/sqlite_date_time.htm) –

回答

0

使用此

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:MM a"); 
String finaltimedate = sdf.format(today); 
0

試試這個使用的語言環境

private String convertDate(String date) { 
      try {  
     SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH); 
       Date d = format.parse(date); 
       SimpleDateFormat serverFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm", Locale.ENGLISH); 
       return serverFormat.format(d); 
    } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    }