Java Parse Date Pattern YYYY parse(String dateText)

Here you can find the source of parse(String dateText)

Description

Converst a String in the format "yyyy-MM-dd" to a Calendar object.

License

Open Source License

Parameter

Parameter Description
dateText The date as a String.

Return

The calendar object, or null if it could not be converted.

Declaration

public static Calendar parse(String dateText) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**// www . ja v  a  2s.  c  o  m
     * Default date format in the form 2013-03-18.
     */
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * Converst a String in the format "yyyy-MM-dd" to a Calendar object.
     * Returns null if the String could not be converted.
     * 
     * @param dateText The date as a String.
     * @return The calendar object, or null if it could not be converted.
     */
    public static Calendar parse(String dateText) {
        try {
            Calendar result = Calendar.getInstance();
            result.setTime(DATE_FORMAT.parse(dateText));
            return result;
        } catch (NullPointerException | ParseException e) {
            return null;
        }
    }
}

Related

  1. parse(String dateString)
  2. parse(String DateString)
  3. parse(String dateString)
  4. parse(String dateString)
  5. parse(String dateString, String dateFormat)
  6. parse(String ds)
  7. parse(String format, String val)
  8. parse(String input)
  9. parse(String original)