I am new to moment.js and the timezone add-on. Hopefully this isn't a duplicate issue, but I am seeming to have some issues with a world clock using moment.js and moment-timezone.js I am trying to make on a page that also is using highcharts. I am using CodePen and a local IDE and seem to be getting two different errors with the same code. Speaking of which, here is the code in question :
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highstock/6.0.3/highstock.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone.min.js"></script>
<label>Texas
<div id = "USclock" class="circle">
<div class="face">
<div id="UShour" class="hour"></div>
<div id="USminute" class="minute"></div>
<div id="USsecond" class="second"></div>
</div>
</div>
</label>
<label> Staffordshire, United Kingdom
<div id = "Ukclock" class="circle">
<div class="face">
<div id="UKhour" class="hour"></div>
<div id="UKminute" class="minute"></div>
<div id="UKsecond" class="second"></div>
</div>
</div>
</label>
And here is the jquery:
$(function() {
function updateClockUS(){
var now = moment(),
second = now.seconds() * 6,
minute = now.minutes() * 6 + second / 60,
hour = ((now.hours() % 12) / 12) * 360 + 90 + minute / 12;
$('#UShour').css("transform", "rotate(" + hour + "deg)");
$('#USminute').css("transform", "rotate(" + minute + "deg)");
$('#USsecond').css("transform", "rotate(" + second + "deg)");
}
function timedUpdate () {
updateClockUS();
setTimeout(timedUpdate, 1000);
}
timedUpdate();
});
$(function() {
function updateClockUK(){
var now = moment().tz("Europe/London"),
second = now.seconds() * 6,
minute = now.minutes() * 6 + second / 60,
hour = ((now.hours() % 12) / 12) * 360 + 90 + minute / 12;
$('#UKhour').css("transform", "rotate(" + hour + "deg)");
$('#UKminute').css("transform", "rotate(" + minute + "deg)");
$('#UKsecond').css("transform", "rotate(" + second + "deg)");
}
function timedUpdate () {
updateClockUK();
setTimeout(timedUpdate, 1000);
}
timedUpdate();
});
May not be important and I know there are some overlapping issues with it, but here is the css:
label {
top: 10%;
right: 10%;
font-size: 30px;
position:fixed;
display: inline-block;
}
.circle {
display: block;
width: 160px;
height: 160px;
margin-top: 10px;
margin-left: -15px;
position: relative;
border: 8px solid black;
border-radius: 50%;
}
.circle .face {
width: 100%;
height: 100%;
}
.circle .face:after {
position: absolute;
top: 50%;
left: 50%;
width: 12px;
height: 12px;
margin: -6px 0 0 -6px;
background: black;
border-radius: 6px;
content: "";
display: block;
}
.circle .face .hour, .circle .face .minute, .circle .face .second {
width: 0;
height: 0;
position: absolute;
top: 50%;
left: 50%;
background: black;
border-radius: 4px 0 0 4px;
}
.circle .face .minute, .circle .face .second {
transform-origin: 50% 100%;
}
.circle .face .hour {
margin: -4px 0 -4px -25%;
padding: 4px 0 4px 25%;
transform-origin: 100% 50%;
}
.circle .face .minute {
margin: -40% -3px 0;
padding: 40% 3px 0;
}
.circle .face .second {
margin: -40% -1px 0 0;
padding: 40% 1px 0;
}
On Chrome Developer Tools I am getting a moment(...).tz is not a function
and on CodePen I am getting "Moment Timezone has no data for Europe/London. See http://momentjs.com/timezone/docs/#/data-loading/."
I used the map on http://momentjs.com/timezone/ to actually use the location so it's not really making sense. On the actual app the UK clock isn't moving at all. Here is the link to the codepen: https://codepen.io/gabedesigns/pen/GXZPqg?editors=1111
Thank you!
I figured it out. Turns out an older input was causing my issues. I am using some Coldfusion templates and that template had an outdated script imported. Thank you though everyone