Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package org.videritis.util;
  2.  
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.Locale;
  7. import java.util.TimeZone;
  8.  
  9. /**
  10. * Methods for dealing with timestamps
  11. */
  12. public class TimestampUtils {
  13.  
  14. /**
  15. * Return an ISO 8601 combined date and time string for current date/time
  16. *
  17. * @return String with format "yyyy-MM-dd'T'HH:mm:ss'Z'"
  18. */
  19. public static String getISO8601StringForCurrentDate() {
  20. Date now = new Date();
  21. return getISO8601StringForDate(now);
  22. }
  23.  
  24. /**
  25. * Return an ISO 8601 combined date and time string for specified date/time
  26. *
  27. * @param date
  28. * Date
  29. * @return String with format "yyyy-MM-dd'T'HH:mm:ss'Z'"
  30. */
  31. private static String getISO8601StringForDate(Date date) {
  32. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
  33. dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
  34. return dateFormat.format(date);
  35. }
  36.  
  37. /**
  38. * Private constructor: class cannot be instantiated
  39. */
  40. private TimestampUtils() {
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement