Java Parse Date Pattern YYYY parse(String str)

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

Description

parse

License

Apache License

Declaration

public static Date parse(String str) throws ParseException 

Method Source Code


//package com.java2s;
/*//from w  ww .j  av  a  2s.  c  om
 * Copyright 2017 StreamSets Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.DateFormat;

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

import java.util.Date;

import java.util.TimeZone;

public class Main {
    private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
    private static final String ISO8601_UTC_MASK = "yyyy-MM-dd'T'HH:mm'Z'";

    public static Date parse(String str) throws ParseException {
        return getISO8601DateFormat().parse(str);
    }

    private static DateFormat getISO8601DateFormat() {
        DateFormat dateFormat = new SimpleDateFormat(ISO8601_UTC_MASK);
        // Stricter parsing to prevent dates such as 2011-12-50T01:00Z (December 50th) from matching
        dateFormat.setLenient(false);
        dateFormat.setTimeZone(UTC);
        return dateFormat;
    }
}

Related

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