Here you can find the source of strongCheckIso8601Date(String date)
public static boolean strongCheckIso8601Date(String date)
//package com.java2s; /**//from w w w. j ava 2 s.c o m * This file is part of the Squashtest platform. * Copyright (C) 2010 - 2016 Henix, henix.fr * * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This 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 3 of the License, or * (at your option) any later version. * * this software 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 software. If not, see <http://www.gnu.org/licenses/>. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String ISO_DATE = "yyyy-MM-dd"; /** * full check of whether the date is a valid iso 8601 date or not. Potentially slower than * #weakCheckIso8601Date but safer. * */ public static boolean strongCheckIso8601Date(String date) { if (date == null) { return false; } else { try { parseIso8601Date(date); return true; } catch (ParseException e) { return false; } } } /** * @param strDate * @return the Date obtained when parsing the argument against pattern yyyy-MM-dd */ public static Date parseIso8601Date(String strDate) throws ParseException { if (strDate == null) { return null; } else { return parseDate(strDate, ISO_DATE); } } private static Date parseDate(String strDatetime, String format) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(strDatetime); } }