Java Timestamp Parse parseTimestamp(Date date)

Here you can find the source of parseTimestamp(Date date)

Description

parse Timestamp

License

Open Source License

Declaration

public static Timestamp parseTimestamp(Date date) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

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

public class Main {

    public static Timestamp parseTimestamp(Date date) {

        if (date == null) {
            return null;
        }//w w w  . j a  v a2  s  .c  o  m
        return new Timestamp(date.getTime());

    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. parseHeaderDate(String timestamp)
  2. parseSnapshotTimestamp(final String tstamp)
  3. parseSQLiteTimestamp(String dd)
  4. parseStopTime(String timestamp, String timezone)
  5. parseTimestamp(Date date)
  6. parseTimestamp(final String format, final String time)
  7. parseTimestamp(final String s)
  8. parseTimeStamp(final String... key)
  9. parseTimestamp(Long time, String pattern)