0

I need to display a worldclock (Time from some contries) using Javascript and retrieving a list from SharePoint. My code is not working could someone help me please. Here's my code. Thanks

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<div id="divListItems"></div>

<script language="JavaScript">

$(function () {
            ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
        });

function retrieveListItems() {

    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Horloge');
    var camlQuery = new SP.CamlQuery();
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded),
    Function.createDelegate(this, this.onQueryFailed)
    );
}       
<!--
function worldClock(zone, region){
var dst = 0
var time = new Date()
var gmtMS = time.getTime() + (time.getTimezoneOffset() * 60000)
var gmtTime = new Date(gmtMS)
var day = gmtTime.getDate()
var month = gmtTime.getMonth()
var year = gmtTime.getYear()
if(year < 1000){
year += 1900
}
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", 
                "September", "October", "November", "December")
var monthDays = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
if (year%4 == 0){
monthDays = new Array("31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
}
if(year%100 == 0 && year%400 != 0){
monthDays = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
}

var hr = gmtTime.getHours() + zone
var min = gmtTime.getMinutes()
var sec = gmtTime.getSeconds()

if (hr >= 24){
hr = hr-24
day -= -1
}
if (hr < 0){
hr -= -24
day -= 1
}
if (hr < 10){
hr = " " + hr
}
if (min < 10){
min = "0" + min
}
if (sec < 10){
sec = "0" + sec
}
if (day <= 0){
if (month == 0){
    month = 11
    year -= 1
    }
    else{
    month = month -1
    }
day = monthDays[month]
}
if(day > monthDays[month]){
    day = 1
    if(month == 11){
    month = 0
    year -= -1
    }
    else{
    month -= -1
    }
}



if (dst == 1){
    hr -= -1
    if (hr >= 24){
    hr = hr-24
    day -= -1
    }
    if (hr < 10){
    hr = " " + hr
    }
    if(day > monthDays[month]){
    day = 1
    if(month == 11){
    month = 0
    year -= -1
    }
    else{
    month -= -1
    }
    }
return monthArray[month] + " " + day + ", " + year + "<br>" + hr + ":" + min + ":" + sec + " DST"
}
else{
return monthArray[month] + " " + day + ", " + year + "<br>" + hr + ":" + min + ":" + sec
}
}

function onQuerySucceeded(sender, args) {

    var t = new Array();
    var oListItem;
    var listItemInfo="";
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        oListItem = listItemEnumerator.get_current();
        listItemInfo +=
        ' <strong>City:</strong> ' + oListItem.get_item('City') +
        ' <strong>Zone:</strong> ' + oListItem.get_item('Zone') +
        ' <strong>TimeZone:</strong> ' + oListItem.get_item('TimeZone') +
        '<br />';
        t.push([oListItem.get_item,oListItem.get_item('Zone'),oListItem.get_item('TimeZone')]);
    }
    $("#divListItems").html(listItemInfo);
    for (i = 0; i < t.length; i++) {
        //marker = new google.maps.Marker({
            //position: new google.maps.LatLng(t[i][1], t[i][2]),
           // map: map
          worldclockZone( document.getElementById(" oListItem.get_item('City')").innerHTML=worldClock(t[i][1],t[i][2]))
        });

window.onload=worldClockZone;

//-->
</script

>

1
  • 1
    so, why isn't it working? You have to be very specific with what's happening. Saying it doesn't work doesn't really tell us a story we can finish.
    – Mike
    Nov 10 '17 at 14:11
0

Not sure what is wrong with the code. I found another site that has javascript to add a clock to a page. I gave it a try and it worked for me. https://www.ricocheting.com/code/javascript/html-generator/date-time-clock

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.