Here you can find the source of parseDateString(String tmp, String format)
Parameter | Description |
---|---|
tmp | Description of the Parameter |
format | Description of the Parameter |
public static java.sql.Date parseDateString(String tmp, String format)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; public class Main { /**// w w w .jav a 2 s. c o m * Takes a string and tries to convert it to a Date * * @param tmp Description of the Parameter * @return Description of the Return Value */ public static java.sql.Date parseDateString(String tmp) { java.sql.Date dateValue = null; try { java.util.Date tmpDate = DateFormat.getDateInstance(DateFormat.SHORT).parse(tmp); dateValue = new java.sql.Date(new java.util.Date().getTime()); dateValue.setTime(tmpDate.getTime()); return dateValue; } catch (Exception e) { try { return java.sql.Date.valueOf(tmp); } catch (Exception e2) { } } return null; } /** * Takes a string and tries to convert it to a Date based on the specified * formatting * * @param tmp Description of the Parameter * @param format Description of the Parameter * @return Description of the Return Value */ public static java.sql.Date parseDateString(String tmp, String format) { java.sql.Date dateValue = null; SimpleDateFormat df = null; df = new SimpleDateFormat(format); try { java.util.Date tmpDate = df.parse(tmp, new ParsePosition(0)); dateValue = new java.sql.Date(new java.util.Date().getTime()); dateValue.setTime(tmpDate.getTime()); return dateValue; } catch (Exception e) { try { return java.sql.Date.valueOf(tmp); } catch (Exception e2) { } } return null; } }