code_junkie

Dates with no time or timezone component in Java/MySQL

Nov 12th, 2011
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public static Date truncateDate(Date date)
  2. {
  3. GregorianCalendar cal = getGregorianCalendar();
  4. cal.set(Calendar.ZONE_OFFSET, 0); // UTC
  5. cal.set(Calendar.DST_OFFSET, 0); // We don't want DST to get in the way.
  6.  
  7. cal.setTime(date);
  8. cal.set(Calendar.MILLISECOND, 0);
  9. cal.set(Calendar.SECOND, 0);
  10. cal.set(Calendar.MINUTE, 0);
  11. cal.set(Calendar.HOUR, 0);
  12. cal.set(Calendar.AM_PM, Calendar.AM);
  13.  
  14. return cal.getTime();
  15. }
  16.  
  17. INSERT INTO time_table(dt) VALUES('2008-12-31')
Add Comment
Please, Sign In to add comment