Java Parse Date parseDate(String s, String format)

Here you can find the source of parseDate(String s, String format)

Description

Utility method to parse a date in the given format

License

Open Source License

Parameter

Parameter Description
s the string to parse
format the date format

Return

a Date representing the date in the passed format

Declaration

public static Date parseDate(String s, String format) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//from ww  w. j  av  a  2  s . c o m
     * Utility method to parse a date in the given format
     * @param s the string to parse
     * @param format the date format
     * @return a Date representing the date in the passed format
     */
    public static Date parseDate(String s, String format) {
        DateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(s);
        } catch (Exception e) {
            throw new RuntimeException("Cannot parse " + s + " into a date using format " + format);
        }
    }
}

Related

  1. parseDate(String s)
  2. parseDate(String s)
  3. parseDate(String s)
  4. parseDate(String s)
  5. parsedate(String s, SimpleDateFormat fmt)
  6. parseDate(String sDate)
  7. parseDate(String sDate)
  8. parseDate(String sDate)
  9. parseDate(String sDate, Locale locale)