Java Parse Date parseDate(Date date)

Here you can find the source of parseDate(Date date)

Description

parse Date

License

Apache License

Parameter

Parameter Description
date a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static String parseDate(Date date) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/* w w  w.j  a v a  2  s  .  co m*/
     * 
     * @param date
     * @return
     * @throws ParseException
     */
    public static Date parseDate(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(date));
        return cal.getTime();
    }

    /**
     * 
     * @param date
     * @return
     * @throws ParseException
     */
    public static String parseDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }
}

Related

  1. parseDate(@Nullable String value)
  2. parseDate(Date date)
  3. parseDate(Date date)
  4. parseDate(Date date)
  5. parseDate(Date date)
  6. parseDate(Date date)
  7. parseDate(Date date, int style, Locale local, boolean withTime)
  8. parseDate(Date date, String format)
  9. parseDate(Date date, String pattern)