是否有可能将string"20110210"转换为java.sql.Date2011-02-10?
我试过了SimpleDateFormat,我得到了java.text.ParseException: Unparseable date: "20110210"
我究竟做错了什么?
我有新的SimpleDateFormat("yyyy-MM-dd")而不是新的SimpleDateFormat("yyyyMMdd")
Dan*_*lan 73
这对我有用而不会抛出异常:
package com.sandbox;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Sandbox {
public static void main(String[] args) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Date parsed = format.parse("20110210");
java.sql.Date sql = new java.sql.Date(parsed.getTime());
}
}
Run Code Online (Sandbox Code Playgroud)