Java String to Date StringtoDate(String dateStr, String format)

Here you can find the source of StringtoDate(String dateStr, String format)

Description

Stringto Date

License

Apache License

Declaration

public static java.util.Date StringtoDate(String dateStr, String format) 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static java.util.Date StringtoDate(String dateStr, String format) {
        Date d = null;//from w ww .ja v  a2s  . c  om
        SimpleDateFormat formater = new SimpleDateFormat(format);
        try {
            formater.setLenient(false);
            d = formater.parse(dateStr);
        } catch (Exception e) {
            // log.error(e);
            d = null;
        }
        return d;
    }

    public static java.util.Date StringtoDate(String dateStr, String format, ParsePosition pos) {
        Date d = null;
        SimpleDateFormat formater = new SimpleDateFormat(format);
        try {
            formater.setLenient(false);
            d = formater.parse(dateStr, pos);
        } catch (Exception e) {
            // log.error(e);
            d = null;
        }
        return d;
    }
}

Related

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