Created
May 27, 2021 17:28
-
-
Save gwsu2008/e2c64704c45b7f57375610b34bb7c8bd to your computer and use it in GitHub Desktop.
java-script-time.js
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<p>Click the button to display the date and time as a string.</p> | |
<button onclick="myFunction()">Try it</button> | |
<p id="demo"></p> | |
<script> | |
function myFunction() { | |
var d = new Date(); | |
var n = d.toLocaleString("en-US"); | |
var offset = d.getTimezoneOffset(); | |
if (offset == 420) { | |
timezone = " PDT" | |
} else if (offset == 480) { | |
timezone = " PST" | |
} else { | |
timezone = "" | |
} | |
document.getElementById("demo").innerHTML = n + timezone; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment