Java SQL Time Parse stringToTime(String schedule)

Here you can find the source of stringToTime(String schedule)

Description

string To Time

License

Apache License

Declaration

public static Time stringToTime(String schedule) 

Method Source Code

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

import java.sql.Time;

public class Main {
    private static final String SEPARATOR = ":";

    public static Time stringToTime(String schedule) {
        if (schedule == null || schedule.isEmpty())
            return null;

        String[] parts = schedule.split(SEPARATOR);
        if (parts.length != 3)
            return null;

        int hour = Integer.parseInt(parts[0]);
        int minute = Integer.parseInt(parts[1]);
        int second = Integer.parseInt(parts[2]);

        if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59)
            return null;

        return new Time(hour, minute, second);
    }/*  w ww .j av  a2  s  .c  o m*/
}

Related

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