Jump to content

Get Time


TheScrub

Recommended Posts

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

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

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...