Java Hour Format formattedStringToDate(String date)

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

Description

Converts a String that represents a Date with the format of DATEPATTERN into a Date-Object

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static Date formattedStringToDate(String date) 

Method Source Code

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

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

public class Main {
    /**/*w  w  w. j  a  va 2  s .  c o m*/
     * Defines the format of each string that represent a date in our project.
     * The pattern is "dd.MM.yyyy HH:mm:ss"
     */
    public static final String DATEPATTERN = "dd.MM.yyyy HH:mm:ss";

    /**
     * Converts a String that represents a Date with the format of DATEPATTERN into a Date-Object
     * @param date
     * @return
     */
    public static Date formattedStringToDate(String date) {
        SimpleDateFormat formatter = new SimpleDateFormat(DATEPATTERN);
        try {
            return formatter.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. formatStrToDate(String strDate, int format)
  2. formatStrToDate(String value, String pattern)
  3. formattedDate()
  4. formattedDate(java.util.Date date, String formatString)
  5. formattedDateToDate(String str)
  6. formattedTime(long epochTime)
  7. formattedTimeForFilenames()
  8. formatterDate(Date date, byte format)
  9. formatterFor(final Thread t)