Java Parse Date Pattern YYYY parse(String s)

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

Description

Parses a date from string.

License

LGPL

Parameter

Parameter Description
s the string representation

Exception

Parameter Description
ParseException on format error

Return

the date

Declaration

public static Date parse(String s) throws ParseException 

Method Source Code


//package com.java2s;
/*//from  w ww  .  j a v  a2  s . co m
 * Copyright 2008-2014, David Karnok 
 * The file is part of the Open Imperium Galactica project.
 * 
 * The code should be distributed under the LGPL license.
 * See http://www.gnu.org/licenses/lgpl.html for details.
 */

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

import java.util.Date;
import java.util.GregorianCalendar;

import java.util.TimeZone;

public class Main {
    /** The date formatter. */
    public static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            sdf.setCalendar(new GregorianCalendar(TimeZone.getTimeZone("GMT")));
            return sdf;
        }
    };

    /**
     * Parses a date from string.
     * @param s the string representation
     * @return the date
     * @throws ParseException on format error
     */
    public static Date parse(String s) throws ParseException {
        return DATE_FORMAT.get().parse(s);
    }
}

Related

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