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.
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>
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
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
| string | format | example |
|---|---|---|
| d | day of month, with leading zero | 01 to 31 |
| D | day of week, three letter abbreviation | Sun to Sat |
| j | day of month, without leading zero | 1 to 31 |
| l (lower-case L) | day of week, full word | Sunday to Saturday |
| N | numeric day of the week | 1 to 7 |
| S | English suffix | st, nd, rd, th |
| w | zero-based day of the week | 0 (Sunday) to 6 |
| z | numeric day of the year | 1-366 |
| F | month, full word | January to December |
| m | month with leading zero | 1 to 12 |
| M | month, three letter abbreviation | Jan to Dec |
| n | month without leading zero | 1 to 12 |
| Y | four-digit year | 1989 or 2014 |
| y | two-digit year | 89 or 14 |
| a | lowercase ante or post meridiem | am or pm |
| A | uppercase ante or post meridiem | AM or PM |
| g | 12-hour format, no leading zero | 1 to 12 |
| G | 24-hour format, no leading zero | 0 to 23 |
| h | 12-hour format, leading zero | 01 to 12 |
| H | 24-hour format, leading zero | 00 to 23 |
| i | minutes, with leading zero | 00 to 59 |
| s | seconds, with leading zero | 00 to 59 |