Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Worldclock .js for SolarWinds in 12hr format
<script language="JavaScript">
<!--
function worldClock(zone, region){
var dst = 0
var time = new Date()
var gmtMS = time.getTime() + (time.getTimezoneOffset() * 60000)
var gmtTime = new Date(gmtMS)
var day = gmtTime.getDate()
var month = gmtTime.getMonth()
var year = gmtTime.getYear()
dd = " AM";
if(year < 1000){
year += 1900
}
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December")
var monthDays = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
if (year%4 == 0){
monthDays = new Array("31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
}
if(year%100 == 0 && year%400 != 0){
monthDays = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
}
var hr = gmtTime.getHours() + zone
var min = gmtTime.getMinutes()
var sec = gmtTime.getSeconds()
if (hr >= 24){
hr = hr-24
day -= -1
}
if (hr < 0){
hr -= -24
day -= 1
}
if (hr < 10){
hr = " " + hr
}
if (min < 10){
min = "0" + min
}
if (sec < 10){
sec = "0" + sec
}
if (day <= 0){
if (month == 0){
month = 11
year -= 1
}
else{
month = month -1
}
day = monthDays[month]
}
if(day > monthDays[month]){
day = 1
if(month == 11){
month = 0
year -= -1
}
else{
month -= -1
}
}
if (region == "NAmerica"){
var startDST = new Date()
var endDST = new Date()
startDST.setMonth(3)
startDST.setHours(2)
startDST.setDate(1)
var dayDST = startDST.getDay()
if (dayDST != 0){
startDST.setDate(8-dayDST)
}
else{
startDST.setDate(1)
}
endDST.setMonth(9)
endDST.setHours(1)
endDST.setDate(31)
dayDST = endDST.getDay()
endDST.setDate(31-dayDST)
var currentTime = new Date()
currentTime.setMonth(month)
currentTime.setYear(year)
currentTime.setDate(day)
currentTime.setHours(hr)
if(currentTime >= startDST && currentTime < endDST){
dst = 1
}
}
if (region == "Europe"){
var startDST = new Date()
var endDST = new Date()
startDST.setMonth(2)
startDST.setHours(1)
startDST.setDate(31)
var dayDST = startDST.getDay()
startDST.setDate(31-dayDST)
endDST.setMonth(9)
endDST.setHours(0)
endDST.setDate(31)
dayDST = endDST.getDay()
endDST.setDate(31-dayDST)
var currentTime = new Date()
currentTime.setMonth(month)
currentTime.setYear(year)
currentTime.setDate(day)
currentTime.setHours(hr)
if(currentTime >= startDST && currentTime < endDST){
dst = 1
}
}
if (dst == 1){
hr -= -1
if (hr >= 24){
hr = hr-24
day -= -1
}
if (hr < 10){
hr = " " + hr
}
if(day > monthDays[month]){
day = 1
if(month == 11){
month = 0
year -= -1
}
else{
month -= -1
}
}
if (hr >= 12) {
hr = hr-12;
dd = " PM";
}
if (hr == 0) {
hr = 12;
}
return monthArray[month] + " " + day + ", " + year + "<br>" + hr + ":" + min + ":" + sec + dd + " DST"
}
else{
if (hr >= 12) {
hr = hr-12;
dd = " PM";
}
if (hr == 0) {
hr = 12;
}
return monthArray[month] + " " + day + ", " + year + "<br>" + hr + ":" + min + ":" + sec + dd
}
}
function worldClockZone(){
document.getElementById("UTC").innerHTML = worldClock(0, "Greenwich")
document.getElementById("Eastern").innerHTML = worldClock(-5, "NAmerica")
document.getElementById("Central").innerHTML = worldClock(-6, "NAmerica")
document.getElementById("Pacific").innerHTML = worldClock(-8, "NAmerica")
setTimeout("worldClockZone()", 1000)
}
window.onload=worldClockZone;
//-->
</script>
<style type="text/css">
.hrow {
vertical-align: middle;
width: 100%;
}
.hrow td {
padding: 5px;
width: 140px;
background-color: #555555;
border: 2px solid #555555;
border-collapse: collapse;
font-family:arial;
color: #ccc;
text-align: center;
font-weight: normal;
}
.hrow td:hover {
background-color: #ff9626;
color: #222222;
border: 2px solid #ff8426;
}
.hrow td:hover h3 {
color: #000000;
}
h3 {
text-transform: uppercase;
display: inline;
color: #ccc;
font-family: arial;
}
</style>
<table>
<tr class="hrow">
<td><h3>Pacific</h3></br><span id="Pacific"></span></td>
<td><h3>Central</h3></br><span id="Central"></span></td>
<td><h3>Eastern</h3></br><span id="Eastern"></span></td>
<td><h3>UTC</h3></br><span id="UTC"></span></td>
</tr>
</table>
@sup3rmark

This comment has been minimized.

Copy link

sup3rmark commented Mar 20, 2017

Looks like the DST bit isn't working here. I can't figure out why, though... any help? Thanks in advance!

@hassan577

This comment has been minimized.

Copy link

hassan577 commented Aug 17, 2018

thank you very much finally I found this code
DEMO
Time In NewYork
Time In London

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.