Java tutorial
//package com.java2s; import java.util.Calendar; public class Main { public static String getTime() { StringBuffer sb = new StringBuffer(); Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); int hour = c.get(Calendar.HOUR_OF_DAY); int minutes = c.get(Calendar.MINUTE); if (hour < 10) { sb.append(0); sb.append(hour); } else { sb.append(hour); } sb.append(':'); if (minutes < 10) { sb.append(0); sb.append(minutes); } else { sb.append(minutes); } return sb.toString(); } }