Java String to Date stringToDate(String dateStr, SimpleDateFormat dateFormat)

Here you can find the source of stringToDate(String dateStr, SimpleDateFormat dateFormat)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String dateStr, SimpleDateFormat dateFormat) 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 {

    public static Date stringToDate(String dateStr, SimpleDateFormat dateFormat) throws ParseException {
        Date date = dateFormat.parse(dateStr);
        return date;
    }//w  w  w . j a  va2 s . com

    public static long parse(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static long parse(String date, String pattern) {

        SimpleDateFormat sdft = new SimpleDateFormat(pattern);
        try {
            return sdft.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}

Related

  1. stringToDate(String date, String pattren)
  2. stringToDate(String datecontent, String format)
  3. stringToDate(String dateStr)
  4. stringToDate(String dateStr)
  5. StringToDate(String dateStr)
  6. StringtoDate(String dateStr, String format)
  7. stringToDate(String dateString)
  8. stringToDate(String dateString)
  9. stringToDate(String dateString)