date set timezone code example
Example 1: javascript set date to timezone
var d = new Date("2020-04-13T00:00:00.000+08:00");
d.toLocaleString('en-US', { timeZone: 'America/New_York' });
Example 2: php change timezone
date_default_timezone_set('America/Los_Angeles');
Example 3: php default timezone
date_default_timezone_set("Asia/Kolkata");
Example 4: javascript set date to timezone
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
convertTZ("2012/04/10 10:10:30 +0000", "Asia/Jakarta")
const convertedDate = convertTZ("2012/04/10 10:10:30 +0000", "Asia/Jakarta")
convertedDate.getHours();
const date = new Date()
convertTZ(date, "Asia/Jakarta")