Posted By

corporem on 10/28/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bobgott


Day of Month


 / Published in: Java
 

  1. public class DateUtils {
  2. private final static Log log = LogFactory.getLog(DateUtils.class);
  3.  
  4. public static Timestamp getTimestampValue(String param) throws ParseException {
  5. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
  6. java.util.Date date = sdf.parse(param);
  7. java.sql.Timestamp timeStampValue = new java.sql.Timestamp(date.getTime());
  8. return timeStampValue;
  9. }
  10.  
  11. public int getIntValue(String param) {
  12. return Integer.parseInt(param);
  13. }
  14.  
  15. public static String getBeforeDateTimestamp(int day) {
  16. Date d = new Date();
  17. SimpleDateFormat formatter;
  18. formatter = new SimpleDateFormat("yyyy-MM-dd");
  19. return formatter.format(new Date(d.getTime() - 60 * 60 * 24 * 1000L * day));
  20. }
  21.  
  22. public static long getCurrentDateTimeMillis() {
  23. Calendar cal = Calendar.getInstance();
  24. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  25. Date date = null;
  26. try {
  27. date = sdf.parse(String.format("%d-%d-%d", cal.get(Calendar.YEAR),
  28. cal.get(Calendar.MONTH) + 1,
  29. cal.get(Calendar.DATE)));
  30. } catch (ParseException e) {
  31. log.fatal(e.getMessage());
  32. }
  33. return date.getTime();
  34. }
  35.  
  36. public static int getDayOfMonth() {
  37. return new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
  38. }
  39.  
  40. public static int getBeforeDayOfMonth(int beforeDay) {
  41. gc.add(gc.DATE, -beforeDay);
  42. return gc.get(Calendar.DAY_OF_MONTH);
  43. }
  44.  
  45. public static int getMinute() {
  46. return new GregorianCalendar().get(Calendar.MINUTE);
  47. }
  48.  
  49. public static int getHourOfDay() {
  50. return new GregorianCalendar().get(Calendar.HOUR_OF_DAY);
  51. }
  52. }

Report this snippet  

You need to login to post a comment.