Java String to Date toDate(String datetime)

Here you can find the source of toDate(String datetime)

Description

to Date

License

Open Source License

Declaration

public static Date toDate(String datetime) 

Method Source Code

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

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

public class Main {
    private static final Date EPOCH = new Date(0);

    public static Date toDate(String datetime) {
        SimpleDateFormat sdf;//from ww  w  .j  a  v  a  2s.c  o m

        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

        try {
            return sdf.parse(datetime);
        } catch (ParseException e) {
            return EPOCH;
        }
    }
}

Related

  1. toDate(String dateString)
  2. toDate(String dateString)
  3. toDate(String dateString, Locale locale)
  4. toDate(String dateString, String dateFormatPattern)
  5. toDate(String dateString, String format)
  6. toDate(String dateToConvert)
  7. toDate(String dateToDatify)
  8. toDate(String dateValue, String format)
  9. toDate(String format, String str)