Java Parse Date parseDate(String dateStr)

Here you can find the source of parseDate(String dateStr)

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String dateStr) 

Method Source Code

//package com.java2s;
/*//from   w w  w  . ja  va  2  s. co m
 * Copyright 2015-2016 RonCoo(http://www.roncoo.com) Group.
 *  
 * 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.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date date = null;
    public static DateFormat dateFormat = null;

    public static Date parseDate(String dateStr, String format) {
        try {
            dateFormat = new SimpleDateFormat(format);
            String dt = dateStr.replaceAll("-", "/");
            dt = dateStr;
            if ((!dt.equals("")) && (dt.length() < format.length())) {
                dt += format.substring(dt.length()).replaceAll("[YyMmDdHhSs]", "0");
            }
            date = (Date) dateFormat.parse(dt);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date parseDate(String dateStr) {
        return parseDate(dateStr, "yyyy-MM-dd");
    }
}

Related

  1. parseDate(String dateStr)
  2. parseDate(String dateStr)
  3. parseDate(String dateStr)
  4. parseDate(String dateStr)
  5. parseDate(String dateStr)
  6. parseDate(String datestr)
  7. parseDate(String dateStr, SimpleDateFormat... formats)
  8. parseDate(String dateStr, String dateFormat)
  9. parseDate(String dateStr, String dateFormat)