Java tutorial
//package com.java2s; /* * Geotoolkit.org - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2009-2012, Open Source Geospatial Foundation (OSGeo) * (C) 2009-2012, Geomatys * * 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; * version 2.1 of the License. * * 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. */ import java.util.Date; import javax.xml.bind.DatatypeConverter; public class Main { /** * Parses a date value from a string. * This method should be used only for occasional parsing. * * @param date The date to parse, or {@code null}. * @return The parsed date, or {@code null} if the given string was null. * @throws IllegalArgumentException If string parameter does not conform to * XML Schema Part 2: Datatypes for {@code xsd:dateTime}. * * @see DatatypeConverter#parseDateTime(String) * * @since 3.06 */ public static Date parseDateTime(final String date) throws IllegalArgumentException { if (date == null) { return null; } return DatatypeConverter.parseDateTime(date).getTime(); } }