Java SQL Date Convert toDBDate(String str)

Here you can find the source of toDBDate(String str)

Description

to DB Date

License

Apache License

Declaration

public static java.sql.Timestamp toDBDate(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String yyyyMMddHHmmssSS = "yyyy-MM-dd HH:mm:ss.SS";

    public static java.sql.Timestamp toDBDate(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(yyyyMMddHHmmssSS);
        try {//  www  .  j  a va 2 s  .  c  o m
            Date date = simpleDateFormat.parse(str);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            return new java.sql.Timestamp(cal.getTimeInMillis());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. to_char(Date date, String format)
  2. to_char(Date date, String format)
  3. toBigDecimal(@Nullable final Date value)
  4. toCalender(final Date aDate)
  5. todaySqlDate()
  6. toEnglishDate(String stringDate)
  7. toGMT(final Date ts)
  8. toInt(java.util.Date v)
  9. toIntDate(Object object, int iDefault)