Java Date to Timestamp dateToTimeStamp(java.util.Date date)

Here you can find the source of dateToTimeStamp(java.util.Date date)

Description

date To Time Stamp

License

Apache License

Declaration

public static Timestamp dateToTimeStamp(java.util.Date date) 

Method Source Code


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

import java.sql.Timestamp;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Timestamp dateToTimeStamp(java.util.Date date) {
        Calendar cal = dateToCalendar(date);
        return calToTimeStamp(cal);
    }/*from  w w  w .  j  a  va  2  s  .com*/

    public static Calendar dateToCalendar(Date date) {
        if (date == null)
            return null;
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }

    public static Timestamp calToTimeStamp(Calendar cal) {
        Timestamp tm = null;
        if (cal == null) {
            tm = null;
        } else {
            tm = new Timestamp(cal.getTime().getTime());
        }

        return tm;
        // return (cal == null) ? null : new
        // Timestamp(cal.getTime().getTime());
    }
}

Related

  1. dateToTimestamp(Date date)
  2. dateToTimestamp(Date date)
  3. DateToTimestamp(Date time)
  4. dateToTimestamp(java.util.Date d)
  5. dateToTimestamp(java.util.Date date)
  6. escapeAsTimestamp(Date date)
  7. getAsTimestampOrEmptyString(Date date)
  8. getAuditTimestamp(Date date)
  9. getDetailedTimeStamp(Date date)