Advertisement
Guest User

Untitled

a guest
May 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5.  
  6. public class Fechas {
  7.  
  8. private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
  9.  
  10. /**
  11. * Chequea si la fecha provista es antes que la fecha recivida.
  12. * @param fecha
  13. * @return
  14. */
  15. public static boolean esPasado(Date fecha) {
  16. return new Date().after(fecha);
  17. }
  18.  
  19. /**
  20. * Chequea si la fecha provista es despues que la fecha recivida.
  21. * @param fecha
  22. * @return
  23. */
  24. public static boolean esFutuo(Date fecha) {
  25. return new Date().before(fecha);
  26. }
  27.  
  28. /**
  29. *
  30. * @return
  31. */
  32. public static Date _5diasdespues() {
  33. final Calendar calendario = Calendar.getInstance();
  34. calendario.add(Calendar.DAY_OF_YEAR, 5);
  35. return calendario.getTime();
  36. }
  37.  
  38. /**
  39. * Devuelve el ultimo dia del mes
  40. * @param fecha
  41. * @return
  42. */
  43. public static Date ultimaDiaDelMes(Date fecha) {
  44. final Calendar calendario = Calendar.getInstance();
  45. calendario.setTime(fecha);
  46. calendario.set(Calendar.DAY_OF_MONTH, calendario.getActualMaximum(Calendar.DAY_OF_MONTH));
  47. fecha = calendario.getTime();
  48. return fecha;
  49. }
  50.  
  51.  
  52. public static String fechaAString(Date fecha) {
  53. return dateFormat.format(fecha);
  54. }
  55.  
  56. public static Date StringAFecha(String fecha) throws Exception {
  57. try {
  58. return dateFormat.parse(fecha);
  59. } catch (ParseException e) {
  60. e.printStackTrace();
  61. throw new Exception("El String no es una fecha");
  62. }
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement