Java Parse Date Pattern YYYY parseYmd(String date)

Here you can find the source of parseYmd(String date)

Description

parse Ymd

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

date, parsed as "yyyy-MM-dd"

Declaration

public static Date parseYmd(String date) 

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 w  ww  .j ava  2s  .  c o m
     * @param date
     * @return date, parsed as "yyyy-MM-dd"
     */
    public static Date parseYmd(String date) {
        return parseDate(date, "yyyy-MM-dd");
    }

    /**
     * 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. parseW3CDateTime(String sDate, Locale locale)
  2. parseWsDate(String date)
  3. parseXEP0082Date(String dateString)
  4. parseXsdDate(final Date date)
  5. parseXsdDateTime(String date)
  6. parseYmd(String s)
  7. parseYmdDate(String dateString)
  8. parseYMDToDate(String dateString)