mini-moment
a mini datetime util
usage
Node.js
npm install mini-moment
const Moment = ;const dateStr = ;
Browser
Require.js
require;;
API
-
date - Date - Date instance of the original moment
-
isToday() - boolean- compare the original moment to today;
-
set(type: "year" | "month" | "date" | "hour" | "second" | "minute" | "week", value: number) - Moment -Mutates the original moment by setting it to a unit of the incoming time
-
next(type: "year" | "month" | "date" | "hour" | "second" | "minute" | "week", delta?: number) - Moment -Mutates the original moment by adding time;
-
prev(type: "year" | "month" | "date" | "hour" | "second" | "minute" | "week", delta?: number) - Moment - Mutates the original moment by subtracting time;
-
get(type: "year" | "month" | "date" | "hour" | "second" | "minute" | "day" | "millisecond") - string - get time unit of the original moment
-
format(formats?: string) - string - format the original moment with format string;
-
fromNow() - string - get the duration string between the original moment and the current time;
-
countDays() - number - get the day count in the month of the original moment
-
startOf(type: "year" | "season" | "month" | "date" | "hour" | "minute" | "week") - Moment - Mutates the original moment by setting it to the start of a unit of time
example
const Moment = ; const year = ;const month = Moment; const timestamp = date; const format = '2016/03/30';const format2 = Moment; const duration = ; const start = '2016/3/30'; const days = '2016/02/01';const days2 = Moment; const next = '2016/03/30'next'date'; const prev = '2016/03/30'; const isToday = now;const isToday2 = Moment; const isValid = Moment;