Problem in displaying time

I have problems to display the time in my project.

  1. How to check whether is 12 am or 12 pm?
  2. How to display time in this format, 00 : 00 am/pm?

Below is the code:


var myDate = new Date();
var hours = myDate.getHours();
if (hours>12) {
	hours -= 12;
             ampm = "pm";
} else {
	if (hours == 0) {
  	   hours = 12;
	}
	   ampm = "am";
}
var min = myDate.getMinutes();
if (min<10) {
	var minutes = "0"+min;
} else {
	minutes = min;
}
timeAccess.text = (hours+":"+minutes+" "+ampm);