npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nmgwap-time-formatting

v0.0.10

Published

时间格式化库

Downloads

41

Readme

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