Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get date in specific timezone

function getTimeFromTimezone(offset) {  
  const currentDate = new Date() //get current time to calculate the UTC time
  let utc = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000) //calculates the UTC time
  let nd = new Date(utc + (3600000*offset)) // get the current timezone with the offset
  return nd
}

getTimeFromTimezone('+5.5').toLocaleString()
getTimeFromTimezone('-3').toLocaleString()
Comment

Get specific timezone time

function calcTime(city, offset) {

    d = new Date();

    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    nd = new Date(utc + (3600000*offset));

    return "The local time in " + city + " is " + nd.toLocaleString();

}

// get Bombay time
console.log(calcTime('Bombay', '+5.5'));

// get Singapore time
console.log(calcTime('Singapore', '+8'));

// get London time
console.log(calcTime('London', '+1'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get folder names with fs 
Javascript :: store input into array javascript 
Javascript :: next router push 
Javascript :: js assignment operators 
Javascript :: how to change background color on scroll 
Javascript :: javascript convert image to base64 
Javascript :: javascript calculator 
Javascript :: increased the value of a counter when a button is clicked in js 
Javascript :: iife js arrow function 
Javascript :: react native counter 
Javascript :: socket.io client send data node js server 
Javascript :: javascript set input value 
Javascript :: javascript keyup event enter key 
Javascript :: mysql remove quote on json extract 
Javascript :: lookup in mongodb array 
Javascript :: javascript document.createElement add function 
Javascript :: get element by id jqueryt 
Javascript :: CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model 
Javascript :: get first duv with jquery 
Javascript :: vue js cdn 
Javascript :: react native only 1 corner rounded 
Javascript :: jquery get 2nd child 
Javascript :: angularjs find and update object in array 
Javascript :: closure in js 
Javascript :: jquery parent 
Javascript :: math.min 
Javascript :: calculate average javascript 
Javascript :: str replace javascript all 
Javascript :: async await javascript stack overflow 
Javascript :: use bootstrap 5 with vue 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =