Here you can find the source of parseTime(String str)
Parameter | Description |
---|---|
str | String. |
First attempts to parse the time in "hh:mm aa" format. If that fails, tries "hh:mm". The latter allows for inputting the time on a 24 clock basis.
static public Date parseTime(String str)
//package com.java2s; /* Please see the license information at the end of this file. */ import java.util.*; import java.text.*; public class Main { /** Timer formatter for dates in format hh:mm aa. */ static private final SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm aa"); /** Timer formatter for dates in format hh:mm . */ static private final SimpleDateFormat timeFormatter2 = new SimpleDateFormat("hh:mm"); /** Parses time of day in hh:mm aa format. *// www. ja va2s . co m * @param str String. * * @return The time, or null if syntax error. * * <p> * First attempts to parse the time in "hh:mm aa" format. * If that fails, tries "hh:mm". The latter allows for * inputting the time on a 24 clock basis. * </p> */ static public Date parseTime(String str) { ParsePosition pos = new ParsePosition(0); Date result = timeFormatter.parse(str, pos); if ((result != null) && (pos.getIndex() < str.length())) result = null; if (result == null) { pos = new ParsePosition(0); result = timeFormatter2.parse(str, pos); if ((result != null) && (pos.getIndex() < str.length())) result = null; } return result; } }