Here you can find the source of getDate(String date)
Parameter | Description |
---|---|
date | date in "dd-MM-yyyy" format |
public static java.sql.Date getDate(String date) throws Exception
//package com.java2s; /*//w ww. j a va 2 s . c o m * @(#)ConversionUtil.java * * Copyright by ObjectFrontier, Inc., * 12225 Broadleaf Lane, Alpharetta, GA 30005, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of ObjectFrontier, Inc. You shall not disclose such Confidential * Information and shall use it only in accordance with the terms of * the license agreement you entered into with ObjectFrontier. */ import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { protected static SimpleDateFormat userDateFmt = new SimpleDateFormat("dd-MM-yyyy"); protected static SimpleDateFormat rtgsUserDateFmt = new SimpleDateFormat("yyyyMMdd"); /** * This method converts date provided as a String into JDBC format. * * @param date date in "dd-MM-yyyy" format * * @return JDBC formatted instance of the day * * throws ParseException will be thrown if the date format of the is invalid */ public static java.sql.Date getDate(String date) throws Exception { try { if ((date == null) || (date.trim().length() == 0)) return null; return new java.sql.Date(userDateFmt.parse(date).getTime()); } catch (ParseException e) { //RBC try { if ((date == null) || (date.trim().length() == 0)) return null; return new java.sql.Date(rtgsUserDateFmt.parse(date).getTime()); } catch (ParseException pe) { throw new Exception( "Invalid Date Format(Expected:DD-MM-YYYY or yyyyMMdd). Check Date, Month & Year."); } } } }