Here you can find the source of StrToDate(String val)
Parameter | Description |
---|---|
val | The date string to be converted |
static public java.util.Date StrToDate(String val)
//package com.java2s; import java.sql.*; import java.util.Calendar; import java.util.StringTokenizer; public class Main { /**/*from w w w. j a v a2 s .com*/ * Convert a string date in the YYYY-MM-DD format into a java.sql.Date * object. * * @param val The date string to be converted * @return A date object matching the string sent in */ static public java.util.Date StrToDate(String val) { Calendar cal = Calendar.getInstance(); if (val != null) { StringTokenizer st = new StringTokenizer(val, "-"); int temp = Integer.parseInt(st.nextToken()); if (temp < 100) { if (temp > 70) { temp += 1900; } else { temp += 2000; } } cal.set(Calendar.YEAR, temp); cal.set(Calendar.MONTH, Integer.parseInt(st.nextToken()) - 1); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(st.nextToken())); } return new Date(cal.getTimeInMillis()); } }