Frontend Development

Clock Script for a Specific Time Zone

Submitted by vicky1360, , Thread ID: 66997

Thread Closed
28-12-2017, 12:04 PM
#1
Code:
function updateClock(){

    var offsetHours = 5;
    var systemDate = new Date();
    var utcOffset = systemDate.getTimezoneOffset() / 60;
    var utc = systemDate.getTime();
    offsetHours += utcOffset;
    var date = new Date(utc + ( 3600000 * offsetHours ) );
    var year = date.getFullYear();
    var month = date.getMonth();
    var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'Jully', 'August', 'September', 'October', 'November', 'December');
    var d = date.getDate();
    var day = date.getDay();
    var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    var amPM = (hours > 11) ? "PM" : "AM";
    if ( hours > 12 ) { hours -= 12; } else if(hours == 0) { hours = "12"; }
    if ( hours < 10 ) { hours = "0" + hours; }
    if ( minutes < 10 ) { minutes = "0" + minutes; }
    if ( seconds < 10 ){ seconds = "0" + seconds; }
    var result = days[day]+', '+months[month]+' '+d+', '+year+' '+hours+':'+minutes+':'+seconds+' '+amPM;
    $("#clock").text(result);
    
  }

To use change offsetHours variable to time zone in hours.

Code:
setInterval(updateClock, 1000);

RE: Clock Script for a Specific Time Zone

#2
This script baset on user OS information? If yes I think more good is geo parametr

RE: Clock Script for a Specific Time Zone

#3
This script baset on user OS information? If yes I think more good is geo parametr

Users browsing this thread: 2 Guest(s)