Description
return a calendar from a cal and time
License
Open Source License
Parameter
Parameter | Description |
---|
c | a parameter |
time | a parameter |
Exception
Parameter | Description |
---|
ParseException | an exception |
Declaration
private static Calendar parseTime(Calendar c, String time)
throws ParseException
Method Source Code
//package com.java2s;
/*//from ww w .j a v a 2 s. c o m
* Copyright (c) 2009 The Regents of the University of California.
* All rights reserved.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the above
* copyright notice and the following two paragraphs appear in all copies
* of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
* CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Main {
/**
* return a calendar from a cal and time
*
* @param c
* @param time
* @return
* @throws ParseException
*/
private static Calendar parseTime(Calendar c, String time)
throws ParseException {
if (time.matches("\\d(\\d)?:\\d(\\d)?")) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
c.setTime(sdf.parse(time));
return c;
} else {
return null;
}
}
}
Related
- parseTime(char[] timeChars)
- ParseTime(final String time)
- parseTime(String currDate, String format)
- parseTime(String date, String format)