Java Parse Date Pattern YYYY parseString(String date)

Here you can find the source of parseString(String date)

Description

Parses a Date to a string using #DATE_STORAGE_FORMAT .

License

Apache License

Parameter

Parameter Description
date The String to parse to a date.

Return

The parsed Date.

Declaration

public static Date parseString(String date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    /**/*  w w w  .  ja  v  a2  s  . co m*/
     * The storage format for parsing dates.
     */
    public static final String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";

    /**
     * Parses a Date to a string using {@link #DATE_STORAGE_FORMAT}.
     *
     * <p>
     * The default storage format is config-friendly, so it may be used in YamlConfig.</p>
     *
     * <p>
     * Parsing <i>never</i> returns null.</p>
     *
     * @param date The String to parse to a date.
     * @return The parsed Date.
     * @see #parseDate(Date)
     */
    public static Date parseString(String date) {
        if (date == null || date.isEmpty() || date.trim().equalsIgnoreCase("never")) {
            return null;
        }
        try {
            return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(date);
        } catch (ParseException ex) {
            return new Date(0L);
        }
    }
}

Related

  1. parseSilently(String p_string)
  2. parseSimpleDate(String string, Date defaultDate)
  3. parseSipDateTime(String dateStr)
  4. parseSolrDate(String date)
  5. parseSpaydDate(String date, TimeZone tz)
  6. parseString(String dateStr)
  7. parseString(String strDate)
  8. parseString2Calendar(String date)
  9. parseString2Date(String date)