Here you can find the source of parseTime(String timeString)
Parameter | Description |
---|---|
timeString | a parameter |
public static Time parseTime(String timeString)
//package com.java2s; import java.sql.Time; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from www . j av a 2s.c o m * parseTime: Returns a Time SQL object corresponding to the given time string. Date portion returned is 1/1/1970 * so the returned Time is only meant to be treated as a Time object. * @param timeString * @return Time */ public static Time parseTime(String timeString) { // Try basic format (e.g. "2:00 AM") Date javaDate = null; try { javaDate = new SimpleDateFormat("hh:mm aaa").parse(timeString); } catch (ParseException e) { } // Try another format if no result yet (e.g. "2 AM") if (javaDate == null) { try { javaDate = new SimpleDateFormat("hh aaa").parse(timeString); } catch (ParseException e) { } } // Try another format if no result yet (e.g. "0200") if (javaDate == null) { try { javaDate = new SimpleDateFormat("HHss").parse(timeString); } catch (ParseException e) { } } if (javaDate == null) throw new IllegalArgumentException("Cannot recognize input as time format: " + timeString); return new Time(javaDate.getTime()); } }