Java Date Parse convertStrToDate(String s, String format)

Here you can find the source of convertStrToDate(String s, String format)

Description

convert Str To Date

License

Open Source License

Declaration

public static Date convertStrToDate(String s, String format) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

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

public class Main {

    public static Date convertStrToDate(String s) {
        try {//from w w  w .ja  v  a 2 s.c o m
            DateFormat dateformat = DateFormat.getDateInstance();
            Date date = dateformat.parse(s);
            return date;
        } catch (Exception exception) {
            exception.printStackTrace();
            Calendar cal = Calendar.getInstance();
            cal.set(1900, 0, 1);
            return cal.getTime();
        }
    }

    public static Date convertStrToDate(String s, String format) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
        try {
            Date date = simpledateformat.parse(s);
            return date;
        } catch (Exception exception) {
            exception.printStackTrace();
            Calendar cal = Calendar.getInstance();
            cal.set(1900, 0, 1);
            return cal.getTime();
        }
    }
}

Related

  1. convertStringToDateWithRFC1123(final String dateTime)
  2. convertStringToTime(String date, String pattern)
  3. convertStringToTime(String date, String pattern)
  4. convertStrToDate(String dateStr, String dateFormat)
  5. convertStrToDate(String day)
  6. convertStrToDate(String source)
  7. convertTFormatToCDATime(String tDate)
  8. convertTimeInMillisecondsToDate(long timeInMilliseconds)
  9. convertTimeStampToDate(String dateString, String srcFormat, String destFormat)