Created
August 19, 2020 02:15
-
-
Save jpalala/e8653bbb5e5deb4756661f58240b1b9a to your computer and use it in GitHub Desktop.
timezone from bombay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getDSTOffset(dst = true) { | |
//DST enabled | |
if(dst) { | |
const dst_offsets = { | |
bombay: 5.5, | |
philippines: 8, | |
london: 1, | |
denver: -6, | |
new_york: -4 | |
} | |
return dst_offsets; | |
} else { | |
//DST disabled | |
const offsets = { | |
bombay: 5.5, | |
philippines: 8, | |
london: 0, | |
denver: -6, | |
new_york: -5 | |
} | |
return offsets; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script type="module"> | |
import { getDSTOffset } from "./dst.js"; | |
function getUTC() { | |
var d = new Date(); | |
var localTime = d.getTime(); | |
var localOffset = d.getTimezoneOffset() * 60 * 1000; | |
// gets current UTC time | |
var utc = localTime + localOffset; | |
console.log(utc); | |
return utc; | |
} | |
var utc = getUTC(); | |
//offset in hoursv | |
var offsets = getDSTOffset(true); | |
var offset_bombay = parseFloat(offsets.bombay); | |
var hour_milliseconds = 3600 * 1000; | |
const bombay = utc + ( hour_milliseconds * offsets.bombay); | |
console.log(bombay); | |
const newDate = new Date(bombay); | |
var bombayTime = newDate.toLocaleString(); | |
const timeIs = "The time in bombay is:" + bombayTime; | |
alert(timeIs); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment