Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get user time using timezone javascript

function calcTime(city, offset) {
    // create Date object for current location
    var d = new Date();

    // convert to msec
    // subtract local time zone offset
    // get UTC time in msec
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    var nd = new Date(utc + (3600000*offset));

    // return time as a string
    return "The local time for city"+ city +" is "+ nd.toLocaleString();
}

alert(calcTime('Bombay', '+5.5'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get value of html element in javascript 
Javascript :: mysql remove quote on json extract 
Javascript :: how to know which button is clicked in jquery 
Javascript :: checkbox jquery checked 
Javascript :: remove all duplicates from an array 
Javascript :: laravel http send data json raw 
Javascript :: Uncaught (in promise) SyntaxError: Unexpected token O in JSON at position 0 
Javascript :: js toggle 
Javascript :: jquery convert time to 1day 2 minutes 4 seconds 
Javascript :: javascript get array difference 
Javascript :: import js in jupyter notebook 
Javascript :: array contains method 
Javascript :: js key value array 
Javascript :: vue js cdn 
Javascript :: how to change the background color of html in javascript 
Javascript :: js bubble sort 
Javascript :: javascript fibonacci example 
Javascript :: queryselectorall javascript images in list 
Javascript :: laravel ajax post data to controller 
Javascript :: request animation frame 
Javascript :: js get day name from date 
Javascript :: remove json javascript 
Javascript :: object.entries 
Javascript :: str replace javascript all 
Javascript :: element clicked js 
Javascript :: log odd numbers js 
Javascript :: chunk an array 
Javascript :: is jwt token expired 
Javascript :: javascript get main color from image 
Javascript :: jquery get all input name and values and submit 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =