[英]java date format wrong response
我正在使用此功能以顯示格式轉換日期。 但是返回錯誤的響應。
date = converDateFormate("yyyy/MM/dd hh:mm:ss", "MM/dd/yyyy hh:mm a","2013/11/28 12:23:28");
Wrong Response: 11/28/2013 12:23 **AM**
Right Response: 11/28/2013 12:23 **PM** (how can I get this response)
public static String converDateFormate(String oldpattern,
String newPattern, String dateString) throws ParseException {
if (dateString != null) {
SimpleDateFormat sdf = new SimpleDateFormat(oldpattern);
Date testDate = null;
testDate = sdf.parse(dateString);
SimpleDateFormat formatter = new SimpleDateFormat(newPattern);
String newFormat = formatter.format(testDate);
System.out.println("" + newFormat);
return newFormat;
} else {
return "";
}
}
在這里查看“中午和午夜的混亂”。 如果您輸入的是24小時格式,則需要在模式中使用HH:mm:ss
。
小錯誤。 而不是日期= converDateFormate(“ yyyy / MM / dd hh:mm:ss”,“ MM / dd / yyyy hh:mm a”,“ 2013/11/28 12:23:28”);
用這個
日期= converDateFormate(“ yyyy / MM / dd HH:mm:ss”,“ MM / dd / yyyy hh:mm a”,“ 2013/11/28 12:23:28”);
舊模式需要更改為24小時制(HH:mm:ss)。
因此,您必須更改以下行:“ date = converDateFormate(” yyyy / MM / dd hh:mm:ss“,” MM / dd / yyyy hh:mm a“,” 2013/11/28 12:23:28“ );“ 到“日期= converDateFormate(“ yyyy / MM / dd HH:mm:ss ”,“ MM / dd / yyyy hh:mm a”,“ 2013/11/28 12:23:28”);“
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.