Convert Utc Time Zone To Local Timezone

[Solved] Convert Utc Time Zone To Local Timezone | Whatever - Code Explorer | yomemimo.com
Question : js UTC to local timezone

Answered by : lonely-llama-d9yyxgwlxp65

// This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);
console.log(d); // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
console.log(d.toLocaleString()); // -> Sat Feb 28 23:45:26 2004
console.log(d.toLocaleDateString()); // -> 02/28/2004
console.log(d.toLocaleTimeString()); // -> 23:45:26 Run code snippet

Source : https://stackoverflow.com/questions/85116/display-date-time-in-users-locale-format-and-time-offset | Last Update : Sun, 07 Nov 21

Question : Convert UTC time zone to local timezone

Answered by : harvindar-singh

from datetime import datetime
from dateutil import tz
# METHOD 1: Hardcode zones:
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('America/New_York')
# METHOD 2: Auto-detect zones:
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
# utc = datetime.utcnow()
utc = datetime.strptime('2011-01-21 02:37:21', '%Y-%m-%d %H:%M:%S')
# Tell the datetime object that it's in UTC time zone since
# datetime objects are 'naive' by default
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
central = utc.astimezone(to_zone)

Source : | Last Update : Sun, 10 Jul 22

Answers related to convert utc time zone to local timezone

Code Explorer Popular Question For Whatever