Java String to Date stringToDate(String datecontent, String format)

Here you can find the source of stringToDate(String datecontent, String format)

Description

Description:Get the date according to specific String content The default format is "yyyy-MM-dd"

License

Open Source License

Parameter

Parameter Description
String a parameter

Return

Date

Declaration

public static Date stringToDate(String datecontent, String format) 

Method Source Code

//package com.java2s;
/*//from  w  w w  .  ja va  2s . c  o  m
 * $RCSfile: DatetimeUtil,v $$
 * $Revision: 1.0  $
 * $Date: 2011  $
 *
 * Copyright (C) 2011 GyTech, Inc. All rights reserved.
 *
 * This software is the proprietary information of GyTech, Inc.
 * Use is subject to license terms.
 */

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

import java.util.Date;

public class Main {
    /**
     * <p>Description:Get the date according to specific String content
     *                      The default format is "yyyy-MM-dd"
     * </p>
     * @param String
     * @return Date
     */
    public static Date stringToDate(String datecontent, String format) {
        if (format == null || format.equals(""))
            format = "yyyy-MM-dd";

        try {
            SimpleDateFormat bartDateFormat = new SimpleDateFormat(format);
            Date date = bartDateFormat.parse(datecontent);
            return date;
        } catch (ParseException pe) {
            @SuppressWarnings("unused")
            String message = "Exception occurs in Parse progress.";
        } catch (Exception e) {
            @SuppressWarnings("unused")
            String message = "Exception occurs during the string converting to Date.";
        }
        return null;
    }
}

Related

  1. stringToDate(String date)
  2. stringToDate(String date)
  3. stringToDate(String date)
  4. stringToDate(String date, String format)
  5. stringToDate(String date, String pattren)
  6. stringToDate(String dateStr)
  7. stringToDate(String dateStr)
  8. StringToDate(String dateStr)
  9. stringToDate(String dateStr, SimpleDateFormat dateFormat)