Get Current Time By Using java.util.Calendar#getInstance()

Below is a simple example for showing how to use Calendar.getInstance() to get current time.

public static String getCurrentTime(){
  Calendar c=Calendar.getInstance();
  String hour="" + c.get(Calendar.HOUR_OF_DAY);
  String min="" + c.get(Calendar.MINUTE);
  String sec="" + c.get(Calendar.SECOND);
  if (hour.length() == 1)   hour="0" + hour;
  if (min.length() == 1)   min="0" + min;
  if (sec.length() == 1)   sec="0" + sec;
  return hour + ":" + min+ ":"+ sec;
}

Reference:

1. java.util.Caldendar

Category >> Others  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>

Leave a comment

*