Java Parse Date parseDate(String date)

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

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String date) 

Method Source Code

//package com.java2s;
/**//from   ww  w.jav  a  2s . co  m
 *  RepDev - RepGen IDE for Symitar
 *  Copyright (C) 2007  Jake Poznanski, Ryan Schultz, Sean Delaney
 *  http://repdev.org/ <support@repdev.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

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

import java.util.Date;

public class Main {
    /**
     * Parse Symitar Dates
     * Date, ex= 05222006
     * Time, ex = 42 = 12:42 AM
     *      ex 2312 = 11:12PM
     * @param date
     * @param time
     * @return
     */
    public static Date parseDate(String dateStr, String time) {

        try {
            if (time == null || time.trim().equals("")) {
                return new SimpleDateFormat("MMddyyyy").parse(dateStr);
            } else {
                DecimalFormat formatter = new DecimalFormat("0000");
                time = formatter.format(Integer.parseInt(time));

                dateStr += time;

                return new SimpleDateFormat("MMddyyyyHHmm").parse(dateStr);
            }
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }

    }

    public static Date parseDate(String date) {
        return parseDate(date, "");
    }
}

Related

  1. parseDate(String date)
  2. parseDate(String date)
  3. parseDate(String date)
  4. parseDate(String date)
  5. parseDate(String date)
  6. parseDate(String date, Locale locale)
  7. parseDate(String date, String expression)
  8. parseDate(String date, String format)
  9. parseDate(String date, String format)