Author - StudySection Post Views - 180 views

Convert Date and time according to the User’s browser time

We need to convert datetime from one timezone to another when we want to save the date and time in one timezone but want to show it on screen according to every user’s browser timezone. For example, if a developer wants to save time according to the “America/Chicago” timezone and wants to show that time in the user’s local timezone(“Asia/Kolkata”) then the below code helps you to convert that.
var DateTime = luxon.DateTime;
var SERVER_TIMEZONE = “America/Chicago”;
const st = DateTime.fromSQL(time,{zone: SERVER_TIMEZONE});
const lt = DateTime.fromMillis(st.ts).toFormat("LL/dd/yyyy hh:mm a" );
const local_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; // gives user’s local browser timezone
let timezone_abbr = "";
timezone_abbr = DateTime.fromObject({year: st.c.year, month: st.c.month, zone: local_timezone})
.toFormat('ZZZZ') //=> "EST"
return lt+" "+timezone_abbr;

jQuery presents a tree-like structure of all the elements on a webpage simplifying the syntax and further manipulating such elements. The jQuery Certification exam by StudySection will secure your fundamental knowledge and a basic understanding of jQuery as an asset to improve your skills.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri