Hot Posts

6/recent/ticker-posts

Get browser timezone

Timezone

Hello developers, during development sometimes we are required to capture users timezone, and according to the timezone name we track users location here I am going to explain steps to get users timezone browser

how many types we can find our timezone

While it can be handled in different ways like database label, server-side label but You can find your timezone in the web browser as below explained

  
  const timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
  console.log(timezoneName ); // Asia/Calcutta

  function getTimezoneDate(timezoneName ){
  let timezoneDate = new Date().toLocaleDateString('en-US', {timeZone: timezoneName });
  return timezoneDate; 
  }

  function getTimezoneTime(timezoneName ){
  let timezoneTime = new Date().toLocaleTimeString('en-US', {timeZone: timezoneName });
  return timezoneTime 
  }
  console.log(getTimezoneDate(timezoneName )); // dinamic
  console.log(getTimezoneTime(timezoneName )); // dinamic

  console.log(getTimezoneDate('America/Denver')); // hard coded for testing
  console.log(getTimezoneTime('America/Denver')); // hard coded for testing

javascript get timezone

I have as list of timezones you can get it to click on below link

Get the full list of UTC timezones