我从服务器返回的时间值为13:00:45:888,它从SAP后端返回为TIME值。如何将其转换为01:00 PM
答案 0 :(得分:1)
You can try the code below.
SimpleDateFormat sdf1 = new SimpleDateFormat("hh:mm a");
SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss:SSS");
Date serverTime = sdf2.parse(ValueFromServer);
ResultYouWant = sdf1.format(serverTime);
答案 1 :(得分:0)
希望这可能会有所帮助
String str = "08:03:10 pm";
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date date = (Date)formatter.parse(str);
或
try {
SimpleDateFormat format = new SimpleDateFormat("hh:mm a"); //if 24 hour format
// or
SimpleDateFormat format = new SimpleDateFormat("HH:mm"); // 12 hour format
java.util.Date d1 =(java.util.Date)format.parse(your_Time);
java.sql.Time ppstime = new java.sql.Time(d1.getTime());
} catch(Exception e) {
Log.e("Exception is ", e.toString());
}