Java SQL Time Parse StringToTime(String strDate)

Here you can find the source of StringToTime(String strDate)

Description

String To Time

License

Apache License

Declaration

public static Date StringToTime(String strDate) throws ParseException 

Method Source Code

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

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

import java.util.Date;

public class Main {
    public static Date StringToTime(String strDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        Date date = sdf.parse(strDate);
        return new java.sql.Date(date.getTime());

    }//from   ww  w.  j  a  va 2  s  . c om

    public static Date getTime() {
        try {
            return getDate("yyyy-MM-dd HH:mm:ss");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getDate() {
        try {
            return getDate("yyyy-MM-dd");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getDate(String format) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = new Date(System.currentTimeMillis());
        return convertStringToDate(df.format(date), format);
    }

    public static Date convertStringToDate(String time, String format)
            throws ParseException {
        if (format == null) {
            format = "yyyy-MM-dd";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.parse(time);
    }
}

Related

  1. string2Time(String dateString)
  2. string2Time(String time, DateFormat timeFormat)
  3. stringToTime(String data, String dateFormat)
  4. stringToTime(String schedule)
  5. stringToTime(String sTime)
  6. stringToTime(String timeString)