Here you can find the source of parseEuropeanDateAnd12HrsTimeString(String aDateString, String aTimeString)
private static Calendar parseEuropeanDateAnd12HrsTimeString(String aDateString, String aTimeString) throws ParseException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { private static Calendar parseEuropeanDateAnd12HrsTimeString(String aDateString, String aTimeString) throws ParseException { String tempStringToParse; if (aDateString != null) { tempStringToParse = aDateString; } else {//from ww w . j av a2 s. co m // use the common "zero" date if no date was given. tempStringToParse = "01.01.1970"; } // append a divider tempStringToParse += "T"; if (aTimeString.length() < 8) { // inject seconds if they're not given; they're optional, but if not present :00 is assumed tempStringToParse += aTimeString.substring(0, aTimeString.length() - 2) + ":00.000" + aTimeString.substring(aTimeString.length() - 2); } else { if (aTimeString.length() < 11) { // inject just milliseconds tempStringToParse += aTimeString.substring(0, aTimeString.length() - 2) + ".000" + aTimeString.substring(aTimeString.length() - 2); } else { tempStringToParse += aTimeString; } } return parseDateOrTimeString(tempStringToParse, "dd.MM.yyyy'T'hh:mm:ss.SSSaa"); } private static Calendar parseDateOrTimeString(String aDateString, String aFormatString) throws ParseException { Calendar tempCalendar = Calendar.getInstance(); tempCalendar.setTime(getSimpleDateFormat(aFormatString).parse(aDateString)); return tempCalendar; } /** * Creates a preconfigured {@link SimpleDateFormat} for the given format string which can be used by the class * internally. * * @param aFormatString * the format string to use * @return the date format instance */ private static SimpleDateFormat getSimpleDateFormat(String aFormatString) { SimpleDateFormat tempFormat = new SimpleDateFormat(aFormatString); tempFormat.setLenient(false); return tempFormat; } }