Java Parse Date Pattern YYYY parseStringToDate(String date)

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

Description

parse String To Date

License

Artistic License

Declaration

public static Date parseStringToDate(String date) throws Exception 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date parseStringToDate(String date) throws Exception {
        Date result = null;/*from w  ww  .j a  v  a 2  s  .  c o m*/
        String parse = date;
        parse = parse.replaceFirst("^[0-9]{4}([^0-9])", "yyyy$1");
        parse = parse.replaceFirst("^[0-9]{2}([^0-9])", "yy$1");
        parse = parse.replaceFirst("([^0-9])[0-9]{1,2}([^0-9])", "$1MM$2");
        parse = parse.replaceFirst("([^0-9])[0-9]{1,2}( ?)", "$1dd$2");
        parse = parse.replaceFirst("( )[0-9]{1,2}([^0-9])", "$1HH$2");
        parse = parse.replaceFirst("([^0-9])[0-9]{1,2}([^0-9])", "$1mm$2");
        parse = parse.replaceFirst("([^0-9])[0-9]{1,2}([^0-9]?)", "$1ss$2");

        SimpleDateFormat format = new SimpleDateFormat(parse);
        result = format.parse(date);
        return result;
    }
}

Related

  1. parseStringDate(String dateAsString)
  2. parseStringDateToRmFormat(String date)
  3. parseStringForDate(String dateString)
  4. parseStringToCalendar(String strDate)
  5. parseStringToDate(final String pDate, final String... pFormat)
  6. parseStringToDate(String dateString)
  7. parseStringToDatePrettyPrint(Date date)
  8. parseStringToUtilDate(String strDate)
  9. parseTIPPDate(String dateString)