Java tutorial
//package com.java2s; /** * This file is part of the au-xml-util package * * Copyright Trenton D. Adams <trenton daught d daught adams at gmail daught ca> * * au-xml-util 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. * * au-xml-util 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 au-xml-util. If not, see <http://www.gnu.org/licenses/>. * * See the COPYING file for more information. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { /** * Converts an XML xs:date string to a Calendar object. We do not mess * around with formatting issues. It either works, or it doesn't. * * @param xsDate the xs:date formatted string * * @return the Calendar object * * @throws ParseException if a parsing error occurs */ public static Calendar xsDateToCalendar(final String xsDate) throws ParseException { Calendar newCal = null; if (xsDate != null) { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); final Date date = dateFormat.parse(xsDate); newCal = Calendar.getInstance(); newCal.setTime(date); } return newCal; } }