[英]Mysql Date Format in Java
我有一個網站,提供2種格式的日期: 28th June 2009
June 2009
28th June 2009
或June 2009
28th June 2009
June 2009
。
現在我想將這兩種格式轉換為使用MySQL和Java的相同格式yyyy-mm-dd hh:mm:ss
。
SimpleDateFormat
給出錯誤:“Unparsable Date”。 解決方案是什么?
那么在June 2009
,您不能通過在這個月 - 年格式中添加一天來說明您需要約會日期。 例如,將這里的第一天添加到1 June 2009
然后以所需的格式進行解析。
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) throws IOException, ParseException
{
String dateStr = "28 June 2009";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(new Date(dateStr)));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.