Java Parse Date Pattern YYYY parse(String source)

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

Description

Null-safe method to create a Calendar from a formatted String .

License

Open Source License

Parameter

Parameter Description
source the formatted String to parse

Return

a

Declaration

public static Calendar parse(String source) throws ParseException 

Method Source Code


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

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

public class Main {
    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    /**/*from  w w  w  . j av a2  s  . c  om*/
     * Null-safe method to create a {@link Calendar} from a formatted {@link String}.
     * <p/>
     * Format template is {@code yyyy-MM-dd'T'HH:mm:ss}.
     *
     * @param source the formatted {@link String} to parse
     * @return a {@link Calendar}
     */
    public static Calendar parse(String source) throws ParseException {
        Calendar cal = Calendar.getInstance();
        cal.setTime(df.parse(source));
        return cal;
    }
}

Related

  1. parse(String s)
  2. parse(String s)
  3. parse(String s)
  4. parse(String s, String formatPattern)
  5. parse(String source)
  6. parse(String source)
  7. parse(String source, Date defaultValue)
  8. parse(String str)
  9. parse(String str)