Java Timestamp Create getTimestamp(String time, String pattern)

Here you can find the source of getTimestamp(String time, String pattern)

Description

get Timestamp

License

Open Source License

Declaration

public static Timestamp getTimestamp(String time, String pattern) 

Method Source Code


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

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static Timestamp getTimestamp(String time) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);/*from  www  .  j a  v  a 2s.  c  o  m*/
        Timestamp ts = null;
        try {
            ts = new Timestamp(format.parse(time).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ts;
    }

    public static Timestamp getTimestamp(String time, String pattern) {
        DateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(false);
        Timestamp ts = null;
        try {
            ts = new Timestamp(format.parse(time).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ts;
    }
}

Related

  1. getTimestamp(String dateString, String format)
  2. getTimestamp(String sqlDateTime)
  3. getTimestamp(String Str)
  4. getTimestamp(String str)
  5. getTimestamp(String strDate)
  6. getTimestamp2()
  7. getTimeStampAsString(Timestamp formatTime)
  8. getTimestampAsString(Timestamp tsTimestamp)
  9. getTimestampAtMidnightForDaysAgo(int days)