且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将字符串dd/MM/yyyy日期转换为java.sql.date yyyy-MM-dd

更新时间:2023-09-20 23:39:34

您应使用SimpleDateFormat(或 Joda Time ),而不是尝试自己解析:

You should use SimpleDateFormat (or the equivalent from Joda Time) rather than trying to parse this yourself:

DateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));

java.util.Date date = format.parse(text);

java.sql.Date sqlDate = new java.sql.Date(date.getTime());