Here you can find the source of parseDate(String dateStr, String format)
Parameter | Description |
---|---|
dateStr | a string of date |
format | a string of date format |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date parseDate(String dateStr, String format) throws ParseException
//package com.java2s; /************************************************************************************ * @File name : Utils.java// w ww .j ava 2 s . co m * * @Author : Brenda Yin * * @Date : 2011-1-24 * * @Copyright Notice: * Copyright (c) 2011 SGM, Inc. All Rights Reserved. * This software is published under the terms of the SGM Software * License version 1.0, a copy of which has been included with this * distribution in the LICENSE.txt file. * * * ---------------------------------------------------------------------------------- * Date Who Version Comments * 2011-1-24 ????12:43:43 Brenda Yin 1.0 Initial Version ************************************************************************************/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Parse the date with the given date string and date format. * * @Date : 2011-6-9 * @param dateStr * a string of date * @param format * a string of date format * @return an instance of Date after parsed * @throws ParseException */ public static Date parseDate(String dateStr, String format) throws ParseException { if (isNullOrEmpty(format) || isNullOrEmpty(dateStr)) { return null; } SimpleDateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.parse(dateStr.trim()); } /** * Check if the input str is null or "" * * @Date : 2011-3-21 * @param str * - string * @return true if str is null or empty; otherwise, false */ public static boolean isNullOrEmpty(String str) { return str == null || str.trim().length() == 0; } }