Get Currnet time as a String


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private String getCurrentTime(){
  2. Calendar c = Calendar.getInstance();
  3. int year = c.get(Calendar.YEAR); //(2)���年���
  4. int month = c.get(Calendar.MONTH) + 1; //(3)�������
  5. int day = c.get(Calendar.DATE); //(4)�������
  6. int hour = c.get(Calendar.HOUR_OF_DAY); //(5)�������
  7. int minute = c.get(Calendar.MINUTE); //(6)�������
  8. int second = c.get(Calendar.SECOND); //(7)�������
  9.  
  10. return (year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second);
  11.  
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.