【npm】一款时间日期工具库,你可以使用它来实现精美日历或欢迎页

时间转换工具

安装

sh 复制代码
npm install v_datejs

引用

javascript 复制代码
import v from "v_datejs";

使用

html:

html 复制代码
<template>
  <code>{{ v.tm() }}</code>
</template>

js:

javascript 复制代码
<script>v.tm();</script>

调用

获取当前时间
javascript 复制代码
v.ct();
console 复制代码
2024/6/13 14:46:32
获取当前时间并补 0
javascript 复制代码
v.ctz();
console 复制代码
2024/06/13 14:46:32
获取当前时间-拼接时间
javascript 复制代码
v.ctc();
console 复制代码
2024-6-13 15:00:34
获取当前时间-拼接时间并补 0
javascript 复制代码
v.ctcz();
console 复制代码
2024-06-13 15:00:34
日期标识符转换
javascript 复制代码
/*
 * @param {String} date
 * @param {String} symbol
 * @example v.dic(date, symbol);
 */
v.dic("2024-01-01", "-");
console 复制代码
2024-01-01
时间戳转换成日期时间
javascript 复制代码
/*
 * @param {*} timestamp
 * @param {String} type
 * @param {Boolean} sup
 * @example v.tm(timestamp, type, sup);
 */
v.tm();
v.tm(new Date(), "date");
v.tm(new Date(), "time");
v.tm(new Date(), "date", true);
v.tm(new Date(), "", true);
v.tm(1718163186898, "time");
v.tm("1718163186898", "time");
v.tm("1718163186898", "date", true);
console 复制代码
2024/6/13 15:03:46
2024/6/13
15:03:46
2024/06/13
2024/06/13 15:03:46
15:03:46
15:03:46
2024/06/13
获取上一周日期
javascript 复制代码
/*
 * @param {String | undefined} date
 * @returns Array
 */
v.lw("2024-6-13");
v.lw();
console 复制代码
["2024/06/03","2024/06/04","2024/06/05","2024/06/06","2024/06/07","2024/06/08","2024/06/09"]
["2024/06/03","2024/06/04","2024/06/05","2024/06/06","2024/06/07","2024/06/08","2024/06/09"]
获取下一周日期
javascript 复制代码
/*
 * @param {String | undefined} date
 * @returns Array
 */
v.nw("2024-6-13");
v.nw();
console 复制代码
["2024/06/17","2024/06/18","2024/06/19","2024/06/20","2024/06/21","2024/06/22","2024/06/23"]
["2024/06/17","2024/06/18","2024/06/19","2024/06/20","2024/06/21","2024/06/22","2024/06/23"]
获取当前周
javascript 复制代码
/*
 * @param {*} date
 * @returns number
 */
v.cw("2024-6-13");
v.cw();
console 复制代码
24
获取今年的天数
javascript 复制代码
/*
 * @param {Number | String | undefined} year
 * @returns number
 */
v.yd("2000");
v.yd(2023);
v.yd();
console 复制代码
366
365
366
获取当前星期几
javascript 复制代码
/*
 * @param {*} date
 * @returns number
 */
v.cdw();
v.cdw(new Date());
v.cdw("2024-6-1");
console 复制代码
星期四
星期四
星期六
有趣的事情
javascript 复制代码
/*
 * @param {String | Number} year
 * @returns Array
 */
v.funny(2019);
v.funny("2019");
console 复制代码
[
  "2019年新冠肺炎疫情爆发",
  "时间:2019年底至2020年初",
  "地点:全国各地",
  "人物:患者、医护人员、政府官员",
  "要素:传染病、防控、医疗资源",
  "事情:新型冠状病毒引发的疫情在中国全国范围内迅速蔓延,造成大量感染和死亡病例。",
  "结果:政府采取了一系列严厉的防控措施,包括封城、隔离、大规模检测等,最终有效控制了疫情的传播。"
]
获取当月的天
javascript 复制代码
/*
 * @param {String | Number | undefined} month
 * @returns Array
 */
v.cmod();
v.cmod("5");
v.cmod(1);
console 复制代码
 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
指定月份日历表
javascript 复制代码
/*
 * @param {String | Number} month
 * @returns Array
 */
v.cmdw(6);
v.cmdw("6");
console 复制代码
[
    {
        "day": 1,
        "active": false,
        "week": "星期六",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-01"
    },
    {
        "day": 2,
        "active": false,
        "week": "星期日",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-02"
    },
    {
        "day": 3,
        "active": false,
        "week": "星期一",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-03"
    },
    {
        "day": 4,
        "active": false,
        "week": "星期二",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-04"
    },
    {
        "day": 5,
        "active": false,
        "week": "星期三",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-05"
    },
    {
        "day": 6,
        "active": false,
        "week": "星期四",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-06"
    },
    {
        "day": 7,
        "active": false,
        "week": "星期五",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-07"
    },
    {
        "day": 8,
        "active": false,
        "week": "星期六",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-08"
    },
    {
        "day": 9,
        "active": false,
        "week": "星期日",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-09"
    },
    {
        "day": 10,
        "active": false,
        "week": "星期一",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-10"
    },
    {
        "day": 11,
        "active": false,
        "week": "星期二",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-11"
    },
    {
        "day": 12,
        "active": false,
        "week": "星期三",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-12"
    },
    {
        "day": 13,
        "active": true,
        "week": "星期四",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-13"
    },
    {
        "day": 14,
        "active": false,
        "week": "星期五",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-14"
    },
    {
        "day": 15,
        "active": false,
        "week": "星期六",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-15"
    },
    {
        "day": 16,
        "active": false,
        "week": "星期日",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-16"
    },
    {
        "day": 17,
        "active": false,
        "week": "星期一",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-17"
    },
    {
        "day": 18,
        "active": false,
        "week": "星期二",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-18"
    },
    {
        "day": 19,
        "active": false,
        "week": "星期三",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-19"
    },
    {
        "day": 20,
        "active": false,
        "week": "星期四",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-20"
    },
    {
        "day": 21,
        "active": false,
        "week": "星期五",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-21"
    },
    {
        "day": 22,
        "active": false,
        "week": "星期六",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-22"
    },
    {
        "day": 23,
        "active": false,
        "week": "星期日",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-23"
    },
    {
        "day": 24,
        "active": false,
        "week": "星期一",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-24"
    },
    {
        "day": 25,
        "active": false,
        "week": "星期二",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-25"
    },
    {
        "day": 26,
        "active": false,
        "week": "星期三",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-26"
    },
    {
        "day": 27,
        "active": false,
        "week": "星期四",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-27"
    },
    {
        "day": 28,
        "active": false,
        "week": "星期五",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-28"
    },
    {
        "day": 29,
        "active": false,
        "week": "星期六",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-29"
    },
    {
        "day": 30,
        "active": false,
        "week": "星期日",
        "month": 6,
        "month_abb": "Jun.",
        "month_ch": "六月",
        "month_en": "June",
        "date": "2024-06-30"
    }
]
获取当前季度
javascript 复制代码
/*
 * @returns String
 */
v.qua();
console 复制代码
{
    "month": [ 4, 5, 6 ],
    "index": 1,
    "quarter": "第二季度"
}
距离新的一年剩余天数(包含当天)
javascript 复制代码
/*
 * @param {String | undefined} date
 * @returns Object
 */
v.surp("2024-12-28");
v.surp();
console 复制代码
{
    "currentDate": "2024/12/28",
    "desc": "距离 2025 年还剩余 4 天",
    "nextYear": 2025,
    "daysRemaining": 4
}
{
    "currentDate": "2024/06/13",
    "desc": "距离 2025 年还剩余 202 天",
    "nextYear": 2025,
    "daysRemaining": 202
}
本月剩余天数(包含当天)
javascript 复制代码
/*
 * @param {String | undefined} date
 * @returns Number
 */
v.nm("2024-1-1");
v.nm("2024-6-30");
v.nm();
v.nm(Date.now());
v.nm(new Date());
console 复制代码
31
1
18
18
18
近三天(包含当天)
javascript 复制代码
/*
 * @param {*} date
 * @param { Number, String } num
 * @returns Array
 */
v.ntd();
v.ntd("2024-01-01");
v.ntd("2025-1-1");
v.ntd(new Date());
v.ntd(Date.now());
v.ntd(1718328252523);
v.ntd(new Date(), 7);
console 复制代码
['2024/06/12', '2024/06/13', '2024/06/14']
['2023/12/30', '2023/12/31', '2024/01/01']
['2024/12/30', '2024/12/31', '2025/01/01']
['2024/06/12', '2024/06/13', '2024/06/14']
['2024/06/12', '2024/06/13', '2024/06/14']
['2024/06/12', '2024/06/13', '2024/06/14']
['2024/06/08', '2024/06/09', '2024/06/10', '2024/06/11', '2024/06/12', '2024/06/13', '2024/06/14']

链接: v_datejs

相关推荐
学不会•1 小时前
css数据不固定情况下,循环加不同背景颜色
前端·javascript·html
活宝小娜4 小时前
vue不刷新浏览器更新页面的方法
前端·javascript·vue.js
程序视点4 小时前
【Vue3新工具】Pinia.js:提升开发效率,更轻量、更高效的状态管理方案!
前端·javascript·vue.js·typescript·vue·ecmascript
coldriversnow4 小时前
在Vue中,vue document.onkeydown 无效
前端·javascript·vue.js
我开心就好o4 小时前
uniapp点左上角返回键, 重复来回跳转的问题 解决方案
前端·javascript·uni-app
开心工作室_kaic5 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic
java·开发语言·前端
刚刚好ā5 小时前
js作用域超全介绍--全局作用域、局部作用、块级作用域
前端·javascript·vue.js·vue
沉默璇年6 小时前
react中useMemo的使用场景
前端·react.js·前端框架
yqcoder6 小时前
reactflow 中 useNodesState 模块作用
开发语言·前端·javascript
2401_882727576 小时前
BY组态-低代码web可视化组件
前端·后端·物联网·低代码·数学建模·前端框架