0.1.4 • Published 8 years ago
sfn-date v0.1.4
SFN-Date
Simple Formatting Nice Date functions for Node.js and browsers.
Install
npm install sfn-date --saveExample
const date = require("sfn-date");
console.log("Y-m-d H:i:s", date("Y-m-d H:i:s"));
console.log("W M d Y H:i:s", date("W M d Y H:i:s"));
console.log("utc", date("utc"));
console.log("iso", date("iso"));
var count = 0;
console.log("\nStart ticking (Y-m-d H:i:s.ms)...");
date.tick("Y-m-d H:i:s.ms", text => {
console.log(text);
count += 1;
if (count === 10)
return false; // break tick.
}, 1000);API
date(format?: string, timestamp?: number)Gets formatted date-time string.formatA format representation carries these symbols:Ythe year with 4 digits;ythe year with 2 digits;Monththe month in English;Mshort-hand month;mthe month, 2 digits with leading zeros;nthe month, 1 or 2 digits without leading zeros;dday of the month, 2 digits with leading zeros;G24-hour format of hours without leading zeros;g12-hour format of hours without leading zeros;H24-hour format hours with leading zeros;h12-hour format hours with leading zeros;iminutes, with leading zeros;sseconds, with leading zeros;msms, with leading zeros;Weekday of the week in English;Wshort-hand week;AAM or PM;aam or pm;gmtGMT date-time string, case-insensitive;utcsame asgmt;isoISO8601 date-time string, case-insensitive.Default value is
Y-m-d H:i:s.
timestampSet a particular UNIX timestamp.
date.tick(format?: string, cb: (dateStr: string) => void, interval?: number): voidRuns a function continuously according to a specific interval.formatis the format asdate().callbackA function called every time reaches the interval, accepts one parameter, which is the current date-time string. If this function returnsfalse, then break the time tick.intervalDefault value is1000ms.
More Details About date.tick()
Unlike the original setInterval() function, this method won't start ticking
immediately, it will firstly wait until the current time reaches a integral
second, and runs the callback once before setting interval.