Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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.
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 |
FAQs
lightweight javascript date formatting
We found that daylight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.