Java Parse Date parseDate(String dateString, String pattern)

Here you can find the source of parseDate(String dateString, String pattern)

Description

Parse a date time String according to a supplied pattern.

License

Open Source License

Parameter

Parameter Description
dateString e.g. 2009-06-17T00:00:00.000
pattern e.g. yyyy-mm-dd'T'HH:mm:ss.SSS

Exception

Parameter Description
Exception ParseException, but also IllegalArgumentException

Return

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT

Declaration

public static long parseDate(String dateString, String pattern) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

public class Main {
    /**//from   ww  w  .  jav a2 s  .  co  m
     * Parse a date time String according to a supplied pattern.
     * @param dateString e.g. 2009-06-17T00:00:00.000
     * @param pattern e.g. yyyy-mm-dd'T'HH:mm:ss.SSS
     * @return Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT 
     * @throws Exception ParseException, but also IllegalArgumentException
     */
    public static long parseDate(String dateString, String pattern) throws Exception {
        return new SimpleDateFormat(pattern).parse(dateString).getTime();
    }
}

Related

  1. parseDate(String dateString)
  2. parseDate(String dateString, Locale locale)
  3. parseDate(String dateString, SimpleDateFormat simpleDateFormat)
  4. parseDate(String dateString, String dateFormat)
  5. parseDate(String dateString, String format, TimeZone zone)
  6. parseDate(String dateText)
  7. parseDate(String datetime)
  8. parseDate(String dateVal)
  9. parseDate(String dateValue)