List of utility methods to do Date to Timestamp
Timestamp | getTimestamp(Date date) get Timestamp return date == null ? null : new Timestamp(date.getTime()); |
Date | getTimestamp(Date date) get Timestamp return date == null ? currentTimestamp() : date;
|
Timestamp | getTimestamp(Date date) get Timestamp return new Timestamp(date.getTime()); |
Timestamp | getTimestamp(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()); |
Timestamp | getTimestamp(Date date) get Timestamp return new Timestamp(date.getTime()); |
Timestamp | getTimestamp(Date date) get Timestamp return new Timestamp(removeMilis(date).getTime()); |
Date | getTimeStamp(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); ... |
Date | removeTimestamp(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; ... |
String | timestamp(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); ... |
String | timestamp(Date d) timestamp if (d == null) return null; return dfDateTime_mmddyyyy.format(d); |