Java Parse Date parseDateOrTimeString(String aDateString, String aFormatString)

Here you can find the source of parseDateOrTimeString(String aDateString, String aFormatString)

Description

parse Date Or Time String

License

Open Source License

Declaration

private static Calendar parseDateOrTimeString(String aDateString, String aFormatString) throws ParseException 

Method Source Code

//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 parseDateOrTimeString(String aDateString, String aFormatString) throws ParseException {
        Calendar tempCalendar = Calendar.getInstance();
        tempCalendar.setTime(getSimpleDateFormat(aFormatString).parse(aDateString));
        return tempCalendar;
    }//from www .ja  va 2  s .  c o  m

    /**
     * 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;
    }
}

Related

  1. parseDateLong(String date, Locale locale)
  2. parseDateLongFormat(String sDate)
  3. parseDateLoose(String dateString)
  4. parseDateNewFormat(String sDate)
  5. parseDateNoTimeWithDelimit(String sDate, String delimit)
  6. parseDateRFC(String value)
  7. parseDateRfc822(String str)
  8. parseDates(String query)
  9. parseDateStrFormat(String strDate)