Here you can find the source of parse(String date)
Parameter | Description |
---|---|
date | The date to parse. |
Parameter | Description |
---|---|
ParseException | if there is an error while parsing the date |
public static Date parse(String date) throws ParseException
//package com.java2s; /******************************************************************************* * Copyright 2010-2016 CNES - CENTRE NATIONAL d'ETUDES SPATIALES * * This file is part of SITools2./* ww w. j a v a2s . c om*/ * * SITools2 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 3 of the License, or * (at your option) any later version. * * SITools2 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. * * You should have received a copy of the GNU General Public License * along with SITools2. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.text.ParseException; import java.util.Date; public class Main { /** * Default date format for date exchange between the server and the client in all the Sitools2 application */ public static final String SITOOLS_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; /** * Parses a formatted date into a Date object with the default date format. * * @param date * The date to parse. * * @return The parsed date. * @throws ParseException * if there is an error while parsing the date */ public static Date parse(String date) throws ParseException { return parse(date, SITOOLS_DATE_FORMAT); } /** * Parses a formatted date into a Date object. * * <p> * An IllegalArgumentException is raised when date is empty or <code>null</code> * </p> * * @param date * The date to parse. * @param format * The format of the date string * @return The parsed date. * @throws ParseException * if there is an error while parsing the date */ public static Date parse(String date, String format) throws ParseException { Date result = null; if (date == null || date.isEmpty()) { throw new IllegalArgumentException("Date is null"); } java.text.DateFormat parser = null; parser = new java.text.SimpleDateFormat(format, java.util.Locale.ROOT); result = parser.parse(date); return result; } }