Java Parse Date parseDate(String dateVal)

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

Description

Parse string to date with default pattern yyyy-MM-dd

License

Open Source License

Parameter

Parameter Description
dateVal string value

Return

date converted from @param dateVal with default pattern

Declaration

public static Date parseDate(String dateVal) 

Method Source Code


//package com.java2s;
/*//from w w w  .  j  a v  a2s  . c o  m
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.util.Date;

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

public class Main {
    /**
     * Parse string to date with specified pattern
     *
     * @param dateVal     string value
     * @param datePattern date pattern
     * @return date converted from @param dateVal with @param datePattern
     */
    public static Date parseDate(String dateVal, String datePattern) {
        Date dateFormatted = null;
        try {
            DateFormat dateFormat = new SimpleDateFormat(datePattern);
            dateFormatted = dateFormat.parse(dateVal);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dateFormatted;
    }

    /**
     * Parse string to date with default pattern                        yyyy-MM-dd
     *
     * @param dateVal string value
     * @return date converted from @param dateVal with default pattern
     */
    public static Date parseDate(String dateVal) {
        return parseDate(dateVal, "yyyy-MM-dd");
    }
}

Related

  1. parseDate(String dateString, String dateFormat)
  2. parseDate(String dateString, String format, TimeZone zone)
  3. parseDate(String dateString, String pattern)
  4. parseDate(String dateText)
  5. parseDate(String datetime)
  6. parseDate(String dateValue)
  7. parseDate(String dateValue)
  8. parseDate(String dateValue, String strFormat)
  9. parseDate(String dttm)