Here you can find the source of parseDate(String dttm)
Parameter | Description |
---|---|
dttm | The date string |
public static Date parseDate(String dttm)
//package com.java2s; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.*; public class Main { /**//from www . j av a2 s.co m * Parse the date. Can be of a number of forms: * <pre> * yyyy-MM-dd HH:mm:ss z yyyy-MM-dd HH:mm:ss yyyy-MM-dd HH:mm * yyyy-MM-dd yyyyMMddHHmmss yyyyMMddHHmm * yyyyMMddHH yyyyMMdd * </pre> * * @param dttm The date string * @return The Date or null if not able to parse it */ public static Date parseDate(String dttm) { String[] formats = { "yyyy-MM-dd HH:mm:ss z", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMMddHH", "yyyyMMdd" }; for (int i = 0; i < formats.length; i++) { SimpleDateFormat dateFormat = new java.text.SimpleDateFormat( formats[i]); dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT")); Date date = dateFormat.parse(dttm, new ParsePosition(0)); if (date != null) { return date; } } return null; } }