TheScrub Posted August 19, 2013 Share Posted August 19, 2013 havet tested in the morning public String getTime(){ Date d = new Date(); int Hour = d.getHours(); int Min= d. getMinutes(); String realMin= null; String realHour = null; String aSide = null; if (Min <10){ realMin="0"+Min; } if (Hour >12){ aSide="PM"; int i = d.getHours()-12; realHour = ""+i; } if (Hour <12){ aSide="AM"; } if (Min >9){ realMin = ""+Min; } String time =realHour+":"+realMin+" "+aSide; return time; //unfinished } Link to comment Share on other sites More sharing options...
bfir3 Posted August 19, 2013 Share Posted August 19, 2013 Or this call: this.toTimeString(System.currentTimeMillis()); private String toTimeString(long time) { return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))); } Link to comment Share on other sites More sharing options...
Cyro Posted August 19, 2013 Share Posted August 19, 2013 Nice there are number of ways to do it My way is public String getTime(){ SimpleDateFormat sdf = new SimpleDateFormat( "hh:mm:ss a"); //a is the pm/am marker Calender calender = Calender.getInstance(); return sdf.format(calendar.getTimer()); } Link to comment Share on other sites More sharing options...