Skip to content

Instantly share code, notes, and snippets.

@dannyid
dannyid / formatTime.js
Last active August 29, 2015 14:04
Format Time
function formatTime(time) {
//time needs to be a Date object like 'new Date()'
var h = time.getHours(),
m = time.getMinutes(),
s = time.getSeconds(),
m = (m < 10 ? '0' : '' ) + m,
s = (s < 10 ? '0' : '' ) + s,
formattedTime = (h > 12 ? h - 12 : (h === 0 ? h + 12 : h)) + ':' + m + ':' + s + (h >= 12 ? ' PM': ' AM');
return formattedTime;
};
@dannyid
dannyid / uri.js
Created July 17, 2014 03:50 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"