Java tutorial
//package com.java2s; /* * Unless explicitly acquired and licensed from Licensor under another license, the contents of * this file are subject to the Reciprocal Public License ("RPL") Version 1.5, or subsequent * versions as allowed by the RPL, and You may not copy or use this file in either source code * or executable form, except in compliance with the terms and conditions of the RPL * * All software distributed under the RPL is provided strictly on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH * WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific language * governing rights and limitations under the RPL. * * http://opensource.org/licenses/RPL-1.5 * * Copyright 2012-2015 Open Justice Broker Consortium */ import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatterBuilder; import org.joda.time.format.DateTimeParser; import org.joda.time.format.ISODateTimeFormat; public class Main { /** * This method accepts an XML date string and will return a JodaTime object. * It will need to be updated to support timezones. * * @param date * @return */ public static final DateTime parseXmlDate(String date) { if (date == null || date.trim().equals("")) { return null; } DateTimeParser[] parsers = new DateTimeParser[] { DateTimeFormat.forPattern("yyyy-MM-dd").getParser(), ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().getParser(), }; DateTimeFormatterBuilder dateTimeFormatterBuilder = new DateTimeFormatterBuilder(); dateTimeFormatterBuilder.append(null, parsers); return dateTimeFormatterBuilder.toFormatter().parseDateTime(date); } }