Get the time in defined format


/ Published in: Java



Copy this code and paste it in your HTML
  1. /**
  2.  * Get the time in defined format
  3.  *
  4.  * @return String with time
  5.  */
  6. public static String getTime() {
  7. String DATE_FORMAT_NOW = "HH:mm:ss";
  8. Calendar cal = Calendar.getInstance();
  9. SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
  10. return sdf.format(cal.getTime());
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.