Java Parse Date Pattern YYYY parseStringDate(String dateAsString)

Here you can find the source of parseStringDate(String dateAsString)

Description

Parses a text date in a thread-safe way.

License

Open Source License

Parameter

Parameter Description
dateAsString A String with the date to be parsed.

Exception

Parameter Description
ParseException if there are problems parsing the date.

Return

a Date with the parsed date.

Declaration

private static Date parseStringDate(String dateAsString)
        throws ParseException 

Method Source Code

//package com.java2s;
/*//from w ww  .j a  v a  2  s.  c o m

 Copyright (c) 2013 Board of Trustees of Leland Stanford Jr. University,
 all rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 Except as contained in this notice, the name of Stanford University shall not
 be used in advertising or otherwise to promote the sale, use or other dealings
 in this Software without prior written authorization from Stanford University.

 */

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private static DateFormat CU_PROPERTY_DATE_PARSER = new SimpleDateFormat(
            "EEE, dd MMM yyyy HH:mm:ss zzz");

    /**
     * Parses a text date in a thread-safe way.
     * 
     * @param dateAsString
     *          A String with the date to be parsed.
     * @return a Date with the parsed date.
     * @throws ParseException
     *           if there are problems parsing the date.
     */
    private static Date parseStringDate(String dateAsString)
            throws ParseException {
        synchronized (CU_PROPERTY_DATE_PARSER) {
            return CU_PROPERTY_DATE_PARSER.parse(dateAsString);
        }
    }
}

Related

  1. parseString2Calendar(String date)
  2. parseString2Date(String date)
  3. parseString2Date(String sDate, String format)
  4. parseString2Long(String strDate)
  5. parseStringAsDate(String pattern, String value)
  6. parseStringDateToRmFormat(String date)
  7. parseStringForDate(String dateString)
  8. parseStringToCalendar(String strDate)
  9. parseStringToDate(final String pDate, final String... pFormat)