Sorry, there are some mistakes in my code. This is the corrected code:
_updateTime() {
var days = ['Sun.','Mon.','Tue.','Wed.','Thu.','Fri.','Sat.'];
var Digital = new Date();
var hours = Digital.getHours();
var minutes = Digital.getMinutes();
var seconds = Digital.getSeconds();
var day = Digital.getDate();
var year = Digital.getFullYear();
var month = Digital.getMonth() + 1;
var pm = 0;
if (hours > 12) {
hours = hours - 12;
pm = 1;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
if (day <= 9) {
day = "0" + day;
}
if (month <= 9) {
month = "0" + month;
}
if pm == 1:
this.time.innerHTML = hours + ":" + minutes + ":" + seconds + "pm";
else:
this.time.innerHTML = hours + ":" + minutes + ":" + seconds + "am";
this.date.innerHTML = days[Digital.getDay()] + " " + day + "." + month + "." + year;
Also, I think there should not be a leading zero to the hour number as I am not adding this like in the original code. I need to be at home to be able to look into this.
In case some aren’t sure why the code for the date disappears for the afternoon times, you’ll need to include the date code in the if statement like the else statement.
I realized last night that 12:00 AM was still showing as 0:00 PM. The “PM” was because of the wrong sign in the code. I had to add an additional couple of lines for when hours = 0. I replaced the code above with what I came up with. I could still end up with midnight incorrectly showing 12:00 PM. It depends on the order expressions are evaluated. I am not a JS wizard so I am not exactly sure.
Keep finding more things. The clock was just reading 2:53 AM and it should be PM. Had to change the order of things. This one seems to work, until I find another issue. I also updated the links above.
Tried your updated code, but added seconds back in on mine, unfortunately any seconds from 0 up 9 just show the single digit instead of the leading zero with it, so the first 10 seconds of any minute always make me do a double take, lol
On mine it is just based on the width of the card. If the card too narrow for the date to fit on the right, it moves it down. I am not sure how to do line breaks in JS