@simplex2-sdk-util/date
v0.0.1
Published
SimpleX2-SDK-Util-Date is a utility library for date manipulation in SimpleX2 SDK.
Downloads
1
Readme
SimpleX2-SDK-Util Date
SimpleX2-SDK-Util-Date is a utility library for date manipulation in SimpleX2 SDK.
Installation
npm install @simplex2-sdk-util/date
Usage
Without SimpleX2 plugin creator
// date.js
import date from '@simplex2-sdk-util/date'
const value = date.formatDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss')
console.log(value)
// 2021-08-01 12:00:00
With SimpleX2 plugin creator
// date.js
import date from '@simplex2-sdk-util/date'
import pluginsManager from '@simplex2-sdk-util/plugins-manager'
pluginsManager.addVuePlugin('date', {
hangInWindow: true,
install: true,
hangInWindowName: 'simplex2UtilSDKDate',
hangInVueName: '$dateSDK',
plugin: (that, Vue, options) => {
return date
}
})
// in Vue2 main.js
import Vue from 'vue'
import App from './App.vue'
import date from './date'
Vue.use(date)
new Vue({
render: h => h(App)
})
// end Vue2 main.js
/* --- or --- */
// in Vue3 main.js
import { createApp } from 'vue'
import App from './App.vue'
import date from './date'
const app = createApp(App)
app.use(date)
app.mount('#app')
// end Vue3 main.js
Methods
formatDateTime
import date from '@simplex2-sdk-util/date'
const value = date.formatDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss')
console.log(value)
// 2021-08-01 12:00:00
formatDate
import date from '@simplex2-sdk-util/date'
const value = date.formatDate(new Date(), 'YYYY-MM-DD')
console.log(value)
// 2021-08-01
formatTime
import date from '@simplex2-sdk-util/date'
const value = date.formatTime(new Date(), 'HH:mm:ss')
console.log(value)
// 12:00:00
getWeek
import date from '@simplex2-sdk-util/date'
const value = date.getWeek(new Date())
console.log(value)
// Monday
getYear
import date from '@simplex2-sdk-util/date'
const value = date.getYear(new Date())
console.log(value)
// 2021
getMonth
import date from '@simplex2-sdk-util/date'
const value = date.getMonth(new Date())
console.log(value)
// 01
getDay
import date from '@simplex2-sdk-util/date'
const value = date.getDay(new Date())
console.log(value)
// 01
getHour
import date from '@simplex2-sdk-util/date'
const value = date.getHour(new Date())
console.log(value)
// 12
getMinute
import date from '@simplex2-sdk-util/date'
const value = date.getMinute(new Date())
console.log(value)
// 00
getSecond
import date from '@simplex2-sdk-util/date'
const value = date.getSecond(new Date())
console.log(value)
// 00
getQuarter
import date from '@simplex2-sdk-util/date'
const value = date.getQuarter(new Date())
console.log(value)
// 1
getDayOfYear
import date from '@simplex2-sdk-util/date'
const value = date.getDayOfYear(new Date())
console.log(value)
// 212
getWeekOfYear
import date from '@simplex2-sdk-util/date'
const value = date.getWeekOfYear(new Date())
console.log(value)
// 31
getDayOfMonth
import date from '@simplex2-sdk-util/date'
const value = date.getDayOfMonth(new Date())
console.log(value)
// 31
getDayOfWeek
import date from '@simplex2-sdk-util/date'
const value = date.getDayOfWeek(new Date())
console.log(value)
// 1
getDaysInMonth
import date from '@simplex2-sdk-util/date'
const value = date.getDaysInMonth(new Date())
console.log(value)
// 31
isLeapYear
import date from '@simplex2-sdk-util/date'
const value = date.isLeapYear(new Date())
console.log(value)
// false
isBefore
import date from '@simplex2-sdk-util/date'
const value = date.isBefore(new Date(), new Date())
console.log(value)
// false
isAfter
import date from '@simplex2-sdk-util/date'
const value = date.isAfter(new Date(), new Date())
console.log(value)
// false
isSame
import date from '@simplex2-sdk-util/date'
const value = date.isSame(new Date(), new Date())
console.log(value)
// true
isSameOrBefore
import date from '@simplex2-sdk-util/date'
const value = date.isSameOrBefore(new Date(), new Date())
console.log(value)
// true
isSameOrAfter
import date from '@simplex2-sdk-util/date'
const value = date.isSameOrAfter(new Date(), new Date())
console.log(value)
// true
isBetween
import date from '@simplex2-sdk-util/date'
const value = date.isBetween(new Date(), new Date(), new Date())
console.log(value)
// false
isDate
import date from '@simplex2-sdk-util/date'
const value = date.isDate(new Date())
console.log(value)
// true
getChineseWeek
import date from '@simplex2-sdk-util/date'
const value = date.getChineseWeek(new Date())
console.log(value)
// 星期一
getChineseMonth
import date from '@simplex2-sdk-util/date'
const value = date.getChineseMonth(new Date())
console.log(value)
// 一月
getAmPm
import date from '@simplex2-sdk-util/date'
const value = date.getAmPm(new Date())
console.log(value)
// AM
addDays
import date from '@simplex2-sdk-util/date'
const value = date.addDays(new Date(), 1)
console.log(value)
// 2020-02-01 12:00:00
addMonths
import date from '@simplex2-sdk-util/date'
const value = date.addMonths(new Date(), 1)
console.log(value)
// 2020-03-01 12:00:00
addYears
import date from '@simplex2-sdk-util/date'
const value = date.addYears(new Date(), 1)
console.log(value)
// 2021-02-01 12:00:00
addHours
import date from '@simplex2-sdk-util/date'
const value = date.addHours(new Date(), 1)
console.log(value)
// 2021-02-01 13:00:00
addMinutes
import date from '@simplex2-sdk-util/date'
const value = date.addMinutes(new Date(), 1)
console.log(value)
// 2021-02-01 12:01:00
addSeconds
import date from '@simplex2-sdk-util/date'
const value = date.addSeconds(new Date(), 1)
console.log(value)
// 2021-02-01 12:00:01
subtractDays
import date from '@simplex2-sdk-util/date'
const value = date.subtractDays(new Date(), 1)
console.log(value)
// 2020-01-31 12:00:00
subtractMonths
import date from '@simplex2-sdk-util/date'
const value = date.subtractMonths(new Date(), 1)
console.log(value)
// 2020-12-01 12:00:00
subtractYears
import date from '@simplex2-sdk-util/date'
const value = date.subtractYears(new Date(), 1)
console.log(value)
// 2019-02-01 12:00:00
subtractHours
import date from '@simplex2-sdk-util/date'
const value = date.subtractHours(new Date(), 1)
console.log(value)
// 2021-02-01 11:00:00
subtractMinutes
import date from '@simplex2-sdk-util/date'
const value = date.subtractMinutes(new Date(), 1)
console.log(value)
// 2021-02-01 11:59:00
subtractSeconds
import date from '@simplex2-sdk-util/date'
const value = date.subtractSeconds(new Date(), 1)
console.log(value)
// 2021-02-01 11:59:59
getFirstDayOfMonth
import date from '@simplex2-sdk-util/date'
const value = date.getFirstDayOfMonth(new Date())
console.log(value)
// 2021-02-01 12:00:00
getLastDayOfMonth
import date from '@simplex2-sdk-util/date'
const value = date.getLastDayOfMonth(new Date())
console.log(value)
// 2021-02-28 12:00:00
getFirstDayOfYear
import date from '@simplex2-sdk-util/date'
const value = date.getFirstDayOfYear(new Date())
console.log(value)
// 2021-01-01 12:00:00
getLastDayOfYear
import date from '@simplex2-sdk-util/date'
const value = date.getLastDayOfYear(new Date())
console.log(value)
// 2021-12-31 12:00:00
getFirstDayOfWeek
import date from '@simplex2-sdk-util/date'
const value = date.getFirstDayOfWeek(new Date())
console.log(value)
// 2021-01-25 12:00:00
getLastDayOfWeek
import date from '@simplex2-sdk-util/date'
const value = date.getLastDayOfWeek(new Date())
console.log(value)
// 2021-01-31 12:00:00
getFirstDayOfQuarter
import date from '@simplex2-sdk-util/date'
const value = date.getFirstDayOfQuarter(new Date())
console.log(value)
// 2021-01-01 12:00:00
getLastDayOfQuarter
import date from '@simplex2-sdk-util/date'
const value = date.getLastDayOfQuarter(new Date())
console.log(value)
// 2021-03-31 12:00:00
getDaysDiff
import date from '@simplex2-sdk-util/date'
const value = date.getDaysDiff(new Date(), new Date())
console.log(value)
// 0
getMonthsDiff
import date from '@simplex2-sdk-util/date'
const value = date.getMonthsDiff(new Date(), new Date())
console.log(value)
// 0
getYearsDiff
import date from '@simplex2-sdk-util/date'
const value = date.getYearsDiff(new Date(), new Date())
console.log(value)
// 0
getHoursDiff
import date from '@simplex2-sdk-util/date'
const value = date.getHoursDiff(new Date(), new Date())
console.log(value)
// 0
getMinutesDiff
import date from '@simplex2-sdk-util/date'
const value = date.getMinutesDiff(new Date(), new Date())
console.log(value)
// 0
getSecondsDiff
import date from '@simplex2-sdk-util/date'
const value = date.getSecondsDiff(new Date(), new Date())
console.log(value)
// 0
isToday
import date from '@simplex2-sdk-util/date'
const value = date.isToday(new Date())
console.log(value)
// true
isYesterday
import date from '@simplex2-sdk-util/date'
const value = date.isYesterday(new Date())
console.log(value)
// false
isTomorrow
import date from '@simplex2-sdk-util/date'
const value = date.isTomorrow(new Date())
console.log(value)
// false
isThisMonth
import date from '@simplex2-sdk-util/date'
const value = date.isThisMonth(new Date())
console.log(value)
// true
isThisYear
import date from '@simplex2-sdk-util/date'
const value = date.isThisYear(new Date())
console.log(value)
// true
isWeekend
import date from '@simplex2-sdk-util/date'
const value = date.isWeekend(new Date())
console.log(value)
// false
getTimestamp
import date from '@simplex2-sdk-util/date'
const value = date.getTimestamp(new Date())
console.log(value)
// 1627814400000
transTimestamp2Date
import date from '@simplex2-sdk-util/date'
const value = date.transTimestamp2Date(1577836800000)
console.log(value)
// 2020-01-01 12:00:00
transDate2Timestamp
import date from '@simplex2-sdk-util/date'
const value = date.transDate2Timestamp('2020-01-01 12:00:00')
console.log(value)
// 1577836800000