Java Date Parse convertStringToDate(String date)

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

Description

convert String To Date

License

Open Source License

Parameter

Parameter Description
date to convert

Exception

Parameter Description
Exception if error

Return

String

Declaration

public static Date convertStringToDate(String date) throws Exception 

Method Source Code

//package com.java2s;
/*/*from www  .  j a  v  a  2s  .  co m*/
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

import java.util.Date;

public class Main {
    /**
     *
     * @param date to convert
     * @return String
     * @throws Exception if error
     */
    public static Date convertStringToDate(String date) throws Exception {
        String pattern = "dd/MM/yyyy HH:mm:ss";
        if (date.length() <= 10) {
            date = date + " 00:00:00";
        }
        return convertStringToTime(date, pattern);
    }

    /**
     *
     * @param date to convert
     * @param pattern in converting
     * @return date
     */
    public static Date convertStringToTime(String date, String pattern) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        try {
            return dateFormat.parse(date);

        } catch (ParseException e) {
            System.out.println("Date ParseException, string value:" + date);
            throw e;
        }
    }
}

Related

  1. convertLongToDate(final long time)
  2. convertStringToDate(String aMask, String strDate)
  3. convertStringToDate(String aMask, String strDate)
  4. convertStringToDate(String arg)
  5. convertStringToDate(String data)
  6. convertStringToDate(String date)
  7. convertStringToDate(String date)
  8. convertStringToDate(String dateAsString)
  9. convertStringToDate(String dateFormat, String date)