/    Sign up×
Community /Pin to ProfileBookmark

Javascript Problem

How do I get this code to use am and pm times instead of the 24 hour clock digits?

`<section class=”openinghours”>
<div class=”openinghourscontent section”>
<div class=”header”>
<h2>Opening hours</h2>
<span id=”open-status”><small class=”openorclosed”>We are</small></span>

</div>
<table class=”opening-hours-table”>
<tr id=”Monday” itemprop=”openingHours” title=”Open Monday at 9am to 6pm”>
<td>Monday</td>
<td class=”opens”>09:00</td>
<td>-</td>
<td class=”closes”>18:00</td>
</tr>
<tr id=”Tuesday” itemprop=”openingHours” title=”Open Tuesday at 9am to 6pm”>
<td>Tuesday</td>
<td class=”opens”>09:00</td>
<td>-</td>
<td class=”closes”>18:00</td>
</tr>
<tr id=”Wednesday” itemprop=”openingHours” title=”Open Wednesday at 9am to 6pm”>
<td>Wednesday</td>
<td class=”opens”>09:00</td>
<td>-</td>
<td class=”closes”>18:00</td>
</tr>
<tr id=”Thursday” itemprop=”openingHours” title=”Open Thursday at 9am to 8pm”>
<td>Thursday</td>
<td class=”opens”>09:00</td>
<td>-</td>
<td class=”closes”>20:00</td>
</tr>
<tr id=”Friday” itemprop=”openingHours” title=”Open Friday at 9am to 6pm”>
<td>Friday</td>
<td class=”opens”>09:00</td>
<td>-</td>
<td class=”closes”>18:00</td>
</tr>
<tr id=”Saturday” itemprop=”openingHours” title=”Open Saturday at 10am to 6pm”>
<td>Saturday</td>
<td class=”opens”>10:00</td>
<td>-</td>
<td class=”closes”>18:00</td>
</tr>
<tr id=”Sunday” itemprop=”openingHours” title=”Open Sunday at 11am to 4pm”>
<td>Sunday</td>
<td class=”opens”>11:00</td>
<td>-</td>
<td class=”closes”>16:00</td>
</tr>
</table>
<button style=”cursor: pointer;” title=”Contact Us” data-appointlet=”u387″>Contact Us</button>
<script>

var currentDate = new Date();
var weekday = [];
weekday[0] = “Sunday”;
weekday[1] = “Monday”;
weekday[2] = “Tuesday”;
weekday[3] = “Wednesday”;
weekday[4] = “Thursday”;
weekday[5] = “Friday”;
weekday[6] = “Saturday”;

var currentDay = weekday[currentDate.getDay()];

var currentTimeHours = currentDate.getHours();
currentTimeHours = currentTimeHours < 10 ? “0” + currentTimeHours : currentTimeHours;
var currentTimeMinutes = currentDate.getMinutes();
var timeNow = currentTimeHours + “” + currentTimeMinutes;

var currentDayID = “#” + currentDay; //gets todays weekday and turns it into id
$(currentDayID).toggleClass(“today”); //this works at hightlighting today

var openTimeSplit = $(currentDayID).children(‘.opens’).text().split(“:”);

var openTimeHours = openTimeSplit[0];
openTimeHours = openTimeHours < 10 ? “0” + openTimeHours : openTimeHours;

var openTimeMinutes = openTimeSplit[1];
var openTimex = openTimeSplit[0] + openTimeSplit[1];

var closeTimeSplit = $(currentDayID).children(‘.closes’).text().split(“:”);

var closeTimeHours = closeTimeSplit[0];
closeTimeHours = closeTimeHours < 10 ? “0” + closeTimeHours : closeTimeHours;

var closeTimeMinutes = closeTimeSplit[1];
var closeTimex = closeTimeSplit[0] + closeTimeSplit[1];

if (timeNow >= openTimex && timeNow <= closeTimex) {
$(“.openorclosed”).toggleClass(“open”);
} else {
$(“.openorclosed”).toggleClass(“closed”);
}
</script>

<script>
(function(e, t, n, r) {
if (e) return;
t._appt = true;
var i = n.createElement(r),
s = n.getElementsByTagName(r)[0];
i.async = true;
i.src = ‘//dje0x8zlxc38k.cloudfront.net/loaders/s-min.js’;
s.parentNode.insertBefore(i, s)
})(window._appt, window, document, “script”)
</script>
</div>

</section> “

to post a comment
HTMLJavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumApr 04.2020 — I recommend to use meaningful names instead of e, t, n, r, i, s.
×

Success!

Help @pods spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...