Java SQL Time Parse string2Time(String time, DateFormat timeFormat)

Here you can find the source of string2Time(String time, DateFormat timeFormat)

Description

string Time

License

Open Source License

Declaration

public static Time string2Time(String time, DateFormat timeFormat) 

Method Source Code


//package com.java2s;
import java.sql.Time;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final DateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    public static final DateFormat DEFAULT_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");

    public static Time string2Time(String time, DateFormat timeFormat) {
        if (time == null)
            return null;
        return new Time(string2Date(time, timeFormat).getTime());
    }/*from   w  w  w .  j a  va  2  s  .co m*/

    public static Time string2Time(String time, String timeFormat) {
        if (time == null)
            return null;
        return new Time(string2Date(time, timeFormat).getTime());
    }

    public static Time string2Time(String time) {
        return string2Time(time, DEFAULT_TIME_FORMAT);
    }

    public synchronized static Date string2Date(String date, DateFormat dateFormat) {
        if (date == null)
            return null;
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }

    public static Date string2Date(String date, String dateFormat) {
        return string2Date(date, new SimpleDateFormat(dateFormat));
    }

    public static Date string2Date(String date) {
        return string2Date(date, DEFAULT_DATE_FORMAT);
    }
}

Related

  1. parseTime(String s)
  2. parseTime(String str)
  3. parseTime(String timeString)
  4. printTime(Time time, String format)
  5. string2Time(String dateString)
  6. stringToTime(String data, String dateFormat)
  7. stringToTime(String schedule)
  8. stringToTime(String sTime)
  9. StringToTime(String strDate)