Java SQL Date Parse strToUtilDate(String fecha, String hora)

Here you can find the source of strToUtilDate(String fecha, String hora)

Description

str To Util Date

License

Open Source License

Declaration

public static java.util.Date strToUtilDate(String fecha, String hora) 

Method Source Code

//package com.java2s;
/********************************************************
  This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version./*  w  ww. j  av  a  2  s .  co  m*/
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************/

public class Main {
    public static java.util.Date strToUtilDate(String fecha, String hora) {
        String f = strToDateFormToDB(fecha) + " " + hora + ":00";
        java.sql.Timestamp dh = java.sql.Timestamp.valueOf(f);
        return (java.util.Date) dh;
    }

    public static String strToDateFormToDB(String fecha) {
        String dateValue = fecha;
        int index = dateValue.indexOf("/");
        String day = dateValue.substring(0, index);
        int index2 = dateValue.indexOf("/", index + 1);
        String month = dateValue.substring(index + 1, index2);
        String year = dateValue.substring(index2 + 1, index2 + 5);
        dateValue = year + "-" + month + "-" + day;
        return dateValue;
    }
}

Related

  1. strToDate(String strDate, String formator)
  2. strToDate(String stringDate)
  3. StrToDate(String val)
  4. strToDate(String value, String pattern)
  5. strToSqlDate(String format, String value)