Here you can find the source of convertToDate(Object o)
Parameter | Description |
---|---|
o | Object to convert |
Parameter | Description |
---|---|
ParseException | if something goes wrong |
public static Date convertToDate(Object o) throws ParseException
//package com.java2s; /*/*from ww w.java 2 s . c o m*/ * NachoCalendar * * Project Info: http://nachocalendar.sf.net * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * Changes * ------- * * 2005-01-09 Cleanups * 2004-12-28 convertToDate: Added null support. * 2004-12-21 Added isToday() funcion * * ------- * * CalendarUtils.java * * Created on October 22, 2004, 10:01 PM */ import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.util.Date; public class Main { private static DateFormat dateformat; /** * Converts Object to Date. * @param o Object to convert * @throws ParseException if something goes wrong * @return a Date */ public static Date convertToDate(Object o) throws ParseException { if (o == null) return null; if (o instanceof Date) { return (Date) o; } if (o instanceof Timestamp) { return new Date(new java.sql.Date(((Timestamp) o).getTime()).getTime()); } if (o instanceof java.sql.Date) { return new Date(((java.sql.Date) o).getTime()); } return dateformat.parse(o.toString()); } }