Java SQL Time From toTime(String format, String str)

Here you can find the source of toTime(String format, String str)

Description

to Time

License

Open Source License

Declaration

public static Timestamp toTime(String format, String str) 

Method Source Code


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

import java.util.Date;

public class Main {
    private static SimpleDateFormat sdf = new SimpleDateFormat();

    public static Timestamp toTime(String format, String str) {
        Date date = toDate(format, str);
        Timestamp timestamp = new Timestamp(date.getTime());
        return timestamp;
    }/*from ww w .  ja v a2 s .co  m*/

    public static Date toDate(String format, String str) {
        Date date = null;
        if (format == null) {
            sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        } else {
            sdf.applyPattern(format);
        }
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. toTime(java.util.GregorianCalendar cal)
  2. toTime(LocalTime localTime)
  3. toTime(LocalTime localTime)
  4. toTime(Object object, Object oDefault)
  5. toTime(Object value)
  6. toTime(String str)
  7. toTime(String value)
  8. toTime2(int value, int fraction, int width)
  9. toTime2(int value, int nanos)