Java String to Date getStringToDate(String date, String format)

Here you can find the source of getStringToDate(String date, String format)

Description

get String To Date

License

Open Source License

Declaration

public static Date getStringToDate(String date, String format) 

Method Source Code

//package com.java2s;
/**//from   w ww .  jav a  2  s .c o m
 * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
 * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * http://www.ewcms.com
 */

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

import java.util.Date;

public class Main {
    private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    public static Date getStringToDate(String date) {
        return getStringToDate(date, DEFAULT_DATE_FORMAT);
    }

    public static Date getStringToDate(String date, String format) {
        SimpleDateFormat simple = new SimpleDateFormat(format);
        try {
            return simple.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. addTimeToDate(String date, int value, String unit, String sFormat)
  2. getStringToDate(String date, String inputDateFormat)
  3. getStringToDate(String pValue, String pDateFormat)
  4. getStringToDate(String str)
  5. getStringToDateFull(String da)