Java Parse Date Pattern YYYY parse(String source, Date defaultValue)

Here you can find the source of parse(String source, Date defaultValue)

Description

parse

License

Apache License

Declaration

static Date parse(String source, Date defaultValue) 

Method Source Code


//package com.java2s;
/*//from w w w . ja va  2  s.c o  m
 * Copyright 2002-2016 the original author or authors.
 *
 * 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.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    static Date parse(String source, Date defaultValue) {
        try {
            return parse(source, "yyyy-MM-dd HH:mm:ss");
        } catch (Exception e) {
            return defaultValue;
        }
    }

    static Date parse(String source) {
        return parse(source, "yyyy-MM-dd HH:mm:ss");
    }

    static Date parse(String source, String format) {
        try {
            return new SimpleDateFormat(format).parse(source);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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