How do I get this to display only the current DATE but within the selected timezone?

Viewed 63

function ctDT(){

var now = new Date(); 
var today = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
var anHour = 1000 * 60 * 60;
today = new Date(today.getTime() - anHour * 5);

var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();

if (hours >= 12){
meridiem = "";
}
else {
meridiem = "";
}


if (minutes<10){
minutes = "0" + minutes;
}
else {
minutes = minutes;
}

if (seconds<10){
seconds = "0" + seconds;
}
else {
seconds = seconds;
}

document.getElementById("ctDT").innerHTML = (hours + ":" + minutes + meridiem);

}

ctDT();
<div id="ctDT"></div>

I'm new to Javascript, but my friend helped me make this display a time. How do I make it display the date instead?

I can see that there is getUTCDate, but when I replace the whole hours + minute section with only date, it comes out wrong.

2 Answers
Related