Skip to content

Instantly share code, notes, and snippets.

@jgable
Last active October 12, 2015 21:39
Show Gist options
  • Save jgable/4091298 to your computer and use it in GitHub Desktop.
Save jgable/4091298 to your computer and use it in GitHub Desktop.
Brief History of Time Code Examples
// Some basic javascript Date examples
// NOTE: Javascript dates have 0 indexed months, because they are awesome
// January 1, 2012 (Chicago, IL)
var firstOfYear = new Date(2012, 0, 1),
// 6 Hour offset (before DST change)
hoursOffset = firstOfYear.getTimezoneOffset() / 60;
// April 1, 2012 (Chicago, IL)
var afterDST = new Date(2012, 3, 1),
// 5 Hour offset (after DST change)
hoursOffset = afterDST.getTimezoneOffset() / 60;
// November 16, 2012 (Chicago, IL)
var postDate = new Date(2012, 10, 16),
// 6 Hour offset (after DST change back)
hoursOffset = postDate.getTimezoneOffset() / 60;
# US central time, represented by Chicago
# Alabama, Arkansas, Florida panhandle (Bay, Calhoun, Escambia,
# Gulf, Holmes, Jackson, Okaloosa, Santa Rosa, Walton, and
# Washington counties), Illinois, western Indiana
# (Gibson, Jasper, Lake, LaPorte, Newton, Porter, Posey, Spencer,
# Vanderburgh, and Warrick counties), Iowa, most of Kansas, western
# Kentucky, Louisiana, Minnesota, Mississippi, Missouri, eastern
# Nebraska, eastern North Dakota, Oklahoma, eastern South Dakota,
# western Tennessee, most of Texas, Wisconsin
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER
Rule Chicago 1920 only - Jun 13 2:00 1:00 D
Rule Chicago 1920 1921 - Oct lastSun 2:00 0 S
Rule Chicago 1921 only - Mar lastSun 2:00 1:00 D
Rule Chicago 1922 1966 - Apr lastSun 2:00 1:00 D
Rule Chicago 1922 1954 - Sep lastSun 2:00 0 S
Rule Chicago 1955 1966 - Oct lastSun 2:00 0 S
var someUTCDate = new Date(),
chicagoWallTime = WallTime.UTCToWallTime(someUTCDate, "America/Chicago"),
backToUTCTIme = WallTime.WallTimeToUTC("America/Chicago", chicagoWallTime);
<script src="/path/to/walltime-data.js"></script>
<script src="/path/to/walltime.js"></script>
<script type="text/javascript">
var rightNow = new Date(),
chicagoWallTime = WallTime.UTCToWallTime(rightNow, "America/Chicago"),
osloWallTime = WallTime.UTCToWallTime(rightNow, "Europe/Oslo"),
backToUTCTime = WallTime.WallTimeToUTC("America/Chicago", chicagoWallTime);
var formatWallTime = function(wt) {
// Format a walltime; 4/26/2013 9:21:13
return [wt.getMonth(), wt.getDate(), wt.getFullYear()].join("/") + " " + [wt.getHours(), wt.getMinutes(), wt.getSeconds()].join(":");
};
console.log("WallTime in Chicago: ", formatWallTime(chicagoWallTime));
console.log("WallTime in Oslo: ", formatWallTime(osloWallTime));
console.log("WallTime in UTC: ", formatWallTime(backToUTCTime));
console.log("BrowserTime: ", formatWallTime(rightNow));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment