Java String to Date StringToDateFormat(String str, String format)

Here you can find the source of StringToDateFormat(String str, String format)

Description

String To Date Format

License

Open Source License

Parameter

Parameter Description
str yyyy-mm-dd

Exception

Parameter Description
ParseException an exception

Return

date

Declaration

public static Date StringToDateFormat(String str, String format) throws ParseException 

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 {
    /**//  ww  w. ja  v  a 2 s . c o m
     * 
     * @param str    yyyy-mm-dd
     * @return date
     * @throws ParseException 
     */
    public static Date StringToDateFormat(String str, String format) throws ParseException {
        Date dt = new Date();
        if (str != null && !str.equals("")) {
            SimpleDateFormat transFormat = new SimpleDateFormat(format);
            dt = transFormat.parse(str);
        }

        return dt;
    }
}

Related

  1. stringToDateAndTime(final String dateAndTimeString)
  2. stringToDateByconf(String str, String formate)
  3. StringToDateByFormat(String dateStr, String formatStr)
  4. StringToDateByformat1(String time)
  5. stringToDateForIng(String date_str)
  6. stringToDateInTimeZone(String time, String timeZone)
  7. stringToDateMetaData(String dateString)
  8. stringToDateTemporalCoverage(String dateString)
  9. stringToDatetime(String str, String format)