# Problem in displaying time

**URL:** <https://forum.kirupa.com/t/problem-in-displaying-time/140883>\
**Category:** Uncategorized\
**Created:** [March 15, 2005, 4:47am UTC](https://forum.kirupa.com/t/problem-in-displaying-time/140883 "2005-03-15T04:47:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![apple](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@apple](https://forum.kirupa.com/u/apple)\
**Post date:** [March 15, 2005, 4:47am UTC](https://forum.kirupa.com/t/problem-in-displaying-time/140883/1 "2005-03-15T04:47:14Z")

</div>

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:

```auto

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);

```
