[Solved] PHP timestamp convert to javascript?


You just need to convert client time to server time zone. Use Date.prototype.getUTCHours and etc methods. Also you can use Date.prototype.getTimezoneOffset() to check the time zone difference and notify use if day changed, for example:

<script>

    var t3=<?php echo $t3; ?>;
    function update_clock3(){

        var now = new Date(Number(t3));
        var year = now.getUTCFullYear();
        var month = now.getUTCMonth();
        var day = now.getUTCDate();
        var hours = now.getUTCHours();
        var minutes = now.getUTCMinutes();
        var seconds = now.getUTCSeconds();  
        //local zone - UTC zone, so +1 UTC will be -60
        var offset = now.getTimezoneOffset()/60;
        //convert hours from UTC time zone to local
        var minutesOffset = offset % 1;
        var localHours = hours - Math.floor(offset);
        var localMinutes = minutes - minutesOffset * 60; 
        var localDate = new Date(year,month, day, localHours, localMinutes, seconds);

        //day can be change by adding offset
        if (localDate.getDate() !== day) {
            alert("You have another day");
        }

        alert("UTC time:" + hours +":"+ minutes + ":" + seconds); 

    }
</script>

3

solved PHP timestamp convert to javascript?