Skip to content

Instantly share code, notes, and snippets.

@allspiritseve
Created December 9, 2016 18:29
Show Gist options
  • Save allspiritseve/0f85c3d07cac85198f36037fd9f8b542 to your computer and use it in GitHub Desktop.
Save allspiritseve/0f85c3d07cac85198f36037fd9f8b542 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//cdn.rawgit.com/bigeasy/timezone/master/src/timezone.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Time</h1>
<script type="text/javascript">
$(document).ready(function() {
var localTime = function(input, format) {
if (!input) { return }
if (!format || typeof format !== 'string') { format = '%F %T' }
/* Local date as UTC, so the browser does not try to do any datezone conversion */
var utc = Date.UTC(input.getFullYear(), input.getMonth(), input.getDate(), input.getHours(), input.getMinutes(), input.getSeconds())
if (isNaN(utc)) { return }
var local = tz(utc, format)
if (typeof local !== 'function') {
return local
}
}
$('time').each(function(i, time) {
var $time = $(time)
var local = localTime(new Date($time.attr('datetime')), $time.data('format'))
if (local) {
$time.html(local)
}
})
})
</script>
<time datetime="<%= @time.utc.strftime('%FT%TZ') %>" data-format="%A, %B %-d, %Y at %-I:%M%P"><%= @time.utc.to_s %></time>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment