Java Date Parse convertDateStringToDB(String date)

Here you can find the source of convertDateStringToDB(String date)

Description

converts date string to db format string (yyyy-MM-dd HH:mm:ss)

License

Open Source License

Parameter

Parameter Description
date a parameter

Exception

Parameter Description
ParseException an exception

Return

String

Declaration

public static String convertDateStringToDB(String date) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.GregorianCalendar;

public class Main {
    public final static String DATE_FORMAT = "dd/MM/yyyy";
    public final static String DATE_FORMAT_DB = "yyyy-MM-dd HH:mm:ss";

    /**/* w w w. j a va 2s. c  o m*/
     * converts date string to db format string (yyyy-MM-dd HH:mm:ss)
     *
     * @param date
     * @return String
     * @throws ParseException
     */
    public static String convertDateStringToDB(String date) throws ParseException {
        GregorianCalendar origDate = new GregorianCalendar();
        SimpleDateFormat sdf1 = new SimpleDateFormat(DATE_FORMAT);
        origDate.setTime(sdf1.parse(date));
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DB);
        String dbFormattedDate = sdf.format(origDate.getTime());
        return dbFormattedDate;
    }
}

Related

  1. asDate(String string)
  2. asDate(String value, String format)
  3. convertDateForExcel(String timestamp)
  4. convertDateFromString(String data)
  5. convertDateStringToDate(String dateString, String format)
  6. convertDateStringToMilliseconds(String dateString)
  7. convertIntToDate(int date)
  8. convertIntToDatePattern2(int date)
  9. convertLongToDate(final long time)