Java Date to Timestamp toDate(String timeStamp)

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

Description

to Date

License

Open Source License

Declaration

public static Date toDate(String timeStamp) 

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 {
    public static Date toDate(String timeStamp) {

        try {/*from   ww w .j  av a  2s .  c  o m*/

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'SSS");
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            return sdf.parse(timeStamp);

        } catch (ParseException e) {

            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                return sdf.parse(timeStamp);

            } catch (ParseException e1) {

                e1.printStackTrace();
                return new Date(0L);

            }
        }
    }
}

Related

  1. timestamp(Date d)
  2. timeStamp(Date date)
  3. timestamp(Date dateAndTime)
  4. timestampSec(Date date)
  5. TimestampToString(Date thisdate)
  6. toDateStringFromResources(String timestamp)
  7. toDateTime(String timeStamp)
  8. unixTimestampToDate(int timestamp)