Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

daylight

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daylight

lightweight javascript date formatting

  • 0.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39
increased by69.57%
Maintainers
1
Weekly downloads
 
Created
Source

daylight

Build Status

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
stringformatexample
dday of month, with leading zero01 to 31
Dday of week, three letter abbreviationSun to Sat
jday of month, without leading zero1 to 31
l (lower-case L)day of week, full wordSunday to Saturday
Nnumeric day of the week1 to 7
SEnglish suffixst, nd, rd, th
wzero-based day of the week0 (Sunday) to 6
znumeric day of the year1-366
Fmonth, full wordJanuary to December
mmonth with leading zero1 to 12
Mmonth, three letter abbreviationJan to Dec
nmonth without leading zero1 to 12
Yfour-digit year1989 or 2014
ytwo-digit year89 or 14
alowercase ante or post meridiemam or pm
Auppercase ante or post meridiemAM or PM
g12-hour format, no leading zero1 to 12
G24-hour format, no leading zero0 to 23
h12-hour format, leading zero01 to 12
H24-hour format, leading zero00 to 23
iminutes, with leading zero00 to 59
sseconds, with leading zero00 to 59

Keywords

FAQs

Package last updated on 30 Dec 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc