Here you can find the source of parseDate(String srtDate, String pattern)
Parameter | Description |
---|---|
srtDate | a parameter |
pattern | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date parseDate(String srtDate, String pattern) throws ParseException
//package com.java2s; /*/*from w w w. j a v a 2s. c o m*/ * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is "EINRC-7 / GDEM project". * * The Initial Developer of the Original Code is TietoEnator. * The Original Code code was developed for the European * Environment Agency (EEA) under the IDA/EINRC framework contract. * * Copyright (C) 2000-2004 by European Environment Agency. All * Rights Reserved. * * Original Code: Kaido Laine (TietoEnator) */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * parses String to Date. * * @param srtDate * @param pattern * @return Date object * @throws ParseException */ public static Date parseDate(String srtDate, String pattern) throws ParseException { if (isNullStr(srtDate)) { return null; } SimpleDateFormat formatter = null; if (pattern == null) { formatter = new SimpleDateFormat(); } else { formatter = new SimpleDateFormat(pattern); } return formatter.parse(srtDate); } /** * Is null or not a String * @param o Object * @return True if Null or not a string */ public static boolean isNullStr(Object o) { if (o == null || !(o instanceof String)) { return true; } return isNullStr((String) o); } /** * Is Null or empty String * @param s String * @return True if Null or empty String */ public static boolean isNullStr(String s) { if (s == null || s.trim().equals("")) { return true; } else { return false; } } }