Here you can find the source of isValidISO8601(String time)
public static boolean isValidISO8601(String time)
//package com.java2s; /* Copyright (c) 2013 Jesper ?qvist <jesper@llbit.se> * * This file is part of Chunky.// ww w .j av a 2s . c o m * * Chunky 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. * * Chunky 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 Chunky. If not, see <http://www.gnu.org/licenses/>. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static boolean isValidISO8601(String time) { if (time.length() < 6) { return false; } try { // insert "GMT" if (time.endsWith("Z")) { time = time.substring(0, time.length() - 1) + "GMT-00:00"; } else { time = time.substring(0, time.length() - 6) + "GMT" + time.substring(time.length() - 6, time.length()); } // http://stackoverflow.com/a/10624878/1250278 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); dateFormat.parse(time); return true; } catch (ParseException e) { return false; } } }