daylight
v0.2.3
Published
lightweight javascript date formatting
Downloads
82
Readme
daylight
I absolutely love the moment.js library, but at times it runs a bit heavier than I really need. I like the simplicity of PHP's built-in date()
function and wrote this to be sort of similar.
usage
note: daylight does a rather rudimentary job parsing dates (strings are just passed through Date.parse()
), so beware of local timezone vs utc time-string pitfalls.
in the browser
TODO: requirejs, commonjs, etc. module support
<script src="daylight.js"></script>
<script>
var today = daylight('l, F jS', Date.now());
var p = document.createElement('p');
p.innerText = today;
document.body.appendChild(p);
//=> <p>Wednesday, May 28th</p>
</script>
using node
install with npm install daylight
, run tests with npm test
, etc.
var daylight = require('daylight');
console.log(daylight('l, F jS', Date.now()));
//=> Wednesday, May 28th
format strings
these are copied from php's date()
function
characters not on this list are passed normally; to escape characters you'll have to use double backslashes:
var today = daylight('\\d\\a\\y: l', Date.now());
console.log(today);
//=> day: Wednesday