Here you can find the source of parseTime(String t)
Parameter | Description |
---|---|
t | Time string. |
static public Date parseTime(String t)
//package com.java2s; /*/*from ww w .j a v a 2s .c o m*/ * IRIS -- Intelligent Roadway Information System * Copyright (C) 2009-2014 Minnesota Department of Transportation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** Time parser formats */ static private final DateFormat[] TIME_FORMATS = { new SimpleDateFormat("h:mm a"), new SimpleDateFormat("H:mm"), new SimpleDateFormat("h a"), new SimpleDateFormat("H") }; /** Parse a time string in one of the supported formats. * @param t Time string. * @return Date object, or null if time could not be parsed. */ static public Date parseTime(String t) { for (DateFormat df : TIME_FORMATS) { try { return df.parse(t); } catch (ParseException e) { /* ignore */ } catch (NumberFormatException e) { /* ignore */ } } return null; } }