为什么setInterval在JavaScript中没有正确地增加我的时钟?

I want to display the actual time in New York. I have a html div:

<div id="time"></div>

and also - I have a php script that returns the actual time:

<?php
  date_default_timezone_set('UTC'); 
  echo time();
?>

and it does it as a timestamp.

Now, I've created a js script:

var serverTime;
        moment.tz.add('America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0');
        function fetchTimeFromServer() {    
             $.ajax({
        type: 'GET', 
        url: 'generalTime.php',
        complete: function(resp){
            serverTime = resp.responseText;

            function updateTimeBasedOnServer(timestamp) { // Take in input the timestamp
                var calculatedTime = moment(timestamp).tz("America/New_York");
                var dateString = calculatedTime.format('h:mm:ss A');
                $('#time').html(dateString + ", ");
            };

            var timestamp = serverTime*1000;
            updateTimeBasedOnServer(timestamp);
            setInterval(function () {
                timestamp += 1000; // Increment the timestamp at every call.
                updateTimeBasedOnServer(timestamp);
            }, 1000);

        }
        })
        };

        fetchTimeFromServer();

        setInterval(function(){
            fetchTimeFromServer();

        }, 5000);

and the idea behind it is that I want to fetch the data from server, display it on my webpage, then increment it every second for five seconds and then fetch the time from the server again (to keep consistence with time on the server). And later on - continue with doing so, fetching the time, incrementing it for 5 seconds, fetching it again, etc.

It works... almost. After the webpage stays open for some time I can see the actual time, but it 'blinks', and I can see that it shows different times - it's hard to explain, but it looks like there is some time already in that div and new time tries to overlay it for each second. Seems like the previous time (content of this div) is not removed... I don't know how to create a jsfiddle with a call to remote server to fetch time from php, so I only have this information pasted above :( What might be the problem here?

Since javascript is single threaded, setInterval may not acutally run your function after the delay. It adds the function to the stack to be run as soon as the processor is ready for it. If the processor has other events in the stack, it will take longer than the interval period to run. Multiple intervals or timeouts are all adding calls to the same stack for processing. To address this, you could use HTML5 web workers or try using setTimeout recursively.

Here is a good read on web workers: https://msdn.microsoft.com/en-us/hh549259.aspx