Java Utililty Methods Date to Timestamp

List of utility methods to do Date to Timestamp

Description

The list of methods to do Date to Timestamp are organized into topic(s).

Method

TimestampgetTimestamp(Date date)
get Timestamp
return date == null ? null : new Timestamp(date.getTime());
DategetTimestamp(Date date)
get Timestamp
return date == null ? currentTimestamp() : date;
TimestampgetTimestamp(Date date)
get Timestamp
return new Timestamp(date.getTime());
TimestampgetTimestamp(Date date)
Creates a java.sql.Timestamp(to match the ones in the database) from the given date.
Calendar gregCal = new GregorianCalendar();
gregCal.setTime(date);
gregCal.set(Calendar.HOUR_OF_DAY, 0);
gregCal.set(Calendar.MINUTE, 0);
gregCal.set(Calendar.SECOND, 0);
gregCal.set(Calendar.MILLISECOND, 0);
return new Timestamp(gregCal.getTime().getTime());
TimestampgetTimestamp(Date date)
get Timestamp
return new Timestamp(date.getTime());
TimestampgetTimestamp(Date date)
get Timestamp
return new Timestamp(removeMilis(date).getTime());
DategetTimeStamp(Date date, String time)
get Time Stamp
if (date == null)
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int hour = Integer.parseInt(time.substring(0, 2));
int minute = Integer.parseInt(time.substring(3));
cal.set(Calendar.HOUR, hour);
cal.set(Calendar.MINUTE, minute);
...
DateremoveTimestamp(Date date)
Removes the timestamp portion of a date
try {
    DateFormat dateFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
    String dateString = dateFormat.format(date);
    return dateFormat.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
return null;
...
Stringtimestamp(Calendar date)
timestamp
DecimalFormat format = new DecimalFormat("00");
int month = date.get(Calendar.MONTH) + 1;
int day = date.get(Calendar.DAY_OF_MONTH);
int hour = date.get(Calendar.HOUR_OF_DAY);
int minute = date.get(Calendar.MINUTE);
int second = date.get(Calendar.SECOND);
return "" + date.get(Calendar.YEAR) + format.format(month) + format.format(day) + format.format(hour)
        + format.format(minute) + format.format(second);
...
Stringtimestamp(Date d)
timestamp
if (d == null)
    return null;
return dfDateTime_mmddyyyy.format(d);