1.0.8 • Published 2 years ago
opdt v1.0.8
OPDT
A tool for operation dates and times.
Import
/* Vue3 */
import opdt from "opdt/index.js";
/* Vue2 */
import opdt from "opdt";
Methods
- formatDate: Format the incoming date.
- getSpecifiedDate: Get the number of days separated from the specified date.
- getRangeDate: Get an array of dates between two dates.
- getDateObject: Split the date into objects.
Params
Params | Description | Type | Default |
---|---|---|---|
date | The date to be formatted, can be set 'Date', 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', etc. | Date\String\Number | new Date() |
format | Specifies the format to return, can be set to 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', 'yyyy 年 MM 月 dd 日', etc. | String | 'yyyy-MM-dd HH:mm:ss' |
Params | Description | Type | Default |
---|---|---|---|
date | The specified date, can be set 'Date', 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', etc. | Date\String\Number | new Date() |
n | The number of days separated from the specified date, it could be negative | Number | 0 |
type | Specifies the type to return, can be set 'date', 'string'. | String | 'date' |
format | Specifies the format to return, can be set to 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', 'yyyy 年 MM 月 dd 日', etc. | String | 'yyyy-MM-dd HH:mm:ss' |
Params | Description | Type | Default |
---|---|---|---|
date1 | Date, can be set 'Date', 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', 'yyyyMMdd', etc. | Date\String\Number | - |
date2 | Date, can be set 'Date', 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', 'yyyyMMdd', etc. | Date\String\Number | - |
type | Specifies the type of each item in the returned array, can be set 'date', 'string'. | String | 'date' |
format | Specifies the format of each item in the returned array, can be set to 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', 'yyyy 年 MM 月 dd 日', etc. | String | 'yyyy-MM-dd HH:mm:ss' |
Params | Description | Type | Default |
---|---|---|---|
date | Date, can be set 'Date', 'yyyy-MM-dd HH:mm:ss', 'yyyyMMdd HHmmss', etc. | Date\String\Number | new Date() |
Usage
/* Vue3 */
import opdt from "opdt/index.js";
/* Vue2 */
import opdt from "opdt";
/* formatDate */
opdt.formatDate("20200602", "yyyy年MM月dd日") // 2020年06月02日
/* getSpecifiedDate */
opdt.getSpecifiedDate("2022-08-13 14:44:23", -1, "string", "yyyy-MM-dd HH:mm:ss") // 2022-08-12 14:44:23
/* getRangeDate */
opdt.getRangeDate("2022/04/17", "2022/04/19", "date") // [2022-04-17T00:00:00.000Z, 2022-04-18T00:00:00.000Z,2022-04-19T00:00:00.000Z]
/* getDateObject */
opdt.getDateObject(new Date()) // {year: '2022', month: '11', day: '10', hour: '15', minute: '38', second: '03'}
Thanks
If you have any questions or need to communicate together, you can add wechat: Hyakkiyakou-0995