Here you can find the source of convertStringToDate(String date)
Parameter | Description |
---|---|
date | to convert |
Parameter | Description |
---|---|
Exception | if error |
public static Date convertStringToDate(String date) throws Exception
//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; } } }