1 Star 1 Fork 0

青年码农 / time-formatting

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

nmgwap-time-formatting

时间格式化插件,返回指定字符串

安装

npm i nmgwap-time-formatting

导入

import {
  getY,
  getM,
  getD,
  getYMD,
  getYMDHM,
  getYMDHMS,
  getMD,
  getHM,
  getHMS,
  getTimeStamp
} from "nmgwap-time-formatting";

获取年

// 获取当前
let y = getY(); // 2022
// 获取指定 - 时间戳
let y = getY(1667801172090); // 2022
// 获取指定 - 字符串格式
let y = getY("2022-10-10"); // 2022
let y = getY("2022-10-10 10:10:10"); // 2022
let y = getY("Mon Nov 07 2022 15:24:23 GMT+0800 (中国标准时间)"); // 2022

获取月

参数同上,自动补全到两位

let m = getM(); // 11

获取日

参数同上,自动补全到两位

let d = getD(); // 01

获取年月日

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“-”,如果是字符串“HZ”,则返回格式为汉字年月日
let ymd = getYMD("2020-10-10", "/"); // 2020/10/10
let ymd = getYMD("2020-10-10", "HZ"); // 2020年10月10日

获取月日

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“-”,如果是字符串“HZ”,则返回格式为汉字月日
let md = getMD("2020-10-10", "/"); // 10/10
let md = getMD("2020-10-10", "HZ"); // 10月10日

获取年月日时分

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“-”,如果是字符串“HZ”,则返回格式为汉字年月日时分
let ymdhm = getYMDHM("2020-10-10", "/"); // 2020/10/10 08:00
let ymdhm = getYMDHM("2020-10-10", "HZ"); // 2020年10月10日08时00分

获取年月日时分秒

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“-”,如果是字符串“HZ”,则返回格式为汉字年月日时分秒
let ymdhms = getYMDHMS("2020-10-10", "/"); // 2020/10/10 08:00:00
let ymdhms = getYMDHMS("2020-10-10", "HZ"); // 2020年10月10日08时00分00秒

获取时分

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“:”,如果是字符串“HZ”,则返回格式为汉字时分
let hm = getHM("2020-10-10", "/"); // 08:00
let hm = getHM("2020-10-10", "HZ"); // 08时00分

获取时分秒

两个参数,都是可选参数

  • date:时间格式,支持字符串、时间戳
  • connector:连接符号,默认“:”,如果是字符串“HZ”,则返回格式为汉字时分秒
let hms = getHMS("2020-10-10", "/"); // 08:00:00
let hms = getHMS("2020-10-10", "HZ"); // 08时00分00分

获取时间戳

一个参数,为可选参数

  • date:时间格式,支持字符串
let timeStamp = getTimeStamp("2020-10-10"); // 1602288000000
MIT License Copyright (c) 2022 青年码农 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

时间格式化插件 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/nmgwap/time-formatting.git
git@gitee.com:nmgwap/time-formatting.git
nmgwap
time-formatting
time-formatting
master

搜索帮助