Here you can find the source of convertDateStringToDB(String date)
Parameter | Description |
---|---|
date | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static String convertDateStringToDB(String date) throws ParseException
//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; } }