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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jotter/dateformat

v1.0.2

Published

Lightweight and easy-to-use date/time formatting function that returns the formatted date/time based on the passed in placeholders.

Downloads

5

Readme

dateFormat

轻巧易用的日期/时间格式化函数。根据传入的占位符返回格式化后的日期/时间。

Lightweight and easy date/time formatting function that returns the formatted date/time based on the passed in placeholders.

Install

npm

npm install @jotter/dateformat

browser

https://cdn.jsdelivr.net/npm/@jotter/dateformat/dist/index.global.js

Usage

import dateFormat from '@jotter/dateformat'

dateFormat(new Date(), 'ddd YYYY/MM/DD HH:mm:ss SSS ZZ')
// Thu 2023/05/25 14:04:25 405 +0800

dateFormat(new Date())
// 2023-05-25 14:05:46

dateFormat(new Date(), 'date')
// '2023-05-25'

dateFormat(new Date(), 'time')
// '13:58:30'

dateFormat('2023/05/25 14:04:25', 'dddd YYYY/MM/DD hh:mm a')
// Thursday 2023/05/25 02:04 pm

dateFormat('2023/05/25 14:04:25', 'YYYY/MM/DD AAh:mm dddd', 'zh')
// 2023/05/25 下午2:04 星期四

dateFormat('2023-5-21', '[Today is] dddd', 'en')
// Today is Sunday

dateFormat('2023-5-25', (date) => {
  return `今天是${date.M}月${date.D}日 星期${date.dd}`
}, 'zh')
// 今天是5月25日 星期四

API

dateFormat(date, formatter, locale)

date

需要格式化的日期/时间。

  • type : Date | string | number

formatter

格式化方式。

  • type : string | Function | 'datetime' | 'date' | 'time'
  • default: datetime

locale

格式化的语言环境,默认为英文。

  • type : 'zh' | 'en'
  • default: en

对照表

  1. 对照表与 moment.js 一致
  2. 将字符放在方括号中,即可原样返回而不被格式化替换 (例如, [MM])

| 占位符 | 输出 | 详情 | | ------ | ------------------------- | ----------------------- | | YY | 23 | 两位数的年份 | | YYYY | 2023 | 四位数的年份 | | M | 1-12 | 月份,从 1 开始 | | MM | 01-12 | 月份,两位数 | | MMM | Jan-Dec 或 [一, 十二] | 简写月份 | | MMMM | October 或 十月 | 完整月份 | | D | 1-31 | 月份里的一天 | | DD | 01-31 | 月份里的一天,两位数 | | Q | 1-4 | 季度(数字) | | QQ | [一, 四] | 季度 (中文) | | d | 0-6 | 周, 星期天是0 (数字) | | dd | Su-Sa 或 [日, 六] | 最简写的星期几 | | ddd | Sun-Sat 或 [周日, 周六] | 简写的星期几 | | dddd | Sunday-Saturday 或 星期几 | 完整的星期几 | | H | 0-23 | 小时 | | HH | 00-23 | 小时,两位数 | | h | 1-12 | 小时, 12 小时制 | | hh | 01-12 | 小时, 12 小时制, 两位数 | | m | 0-59 | 分钟 | | mm | 00-59 | 分钟,两位数 | | s | 0-59 | 秒 | | ss | 00-59 | 秒, 两位数 | | S | 0-9 | 毫秒 (后1位) | | SS | 00-99 | 毫秒 (后2位) | | SSS | 000-999 | 毫秒 (3位) | | Z | +05:00 | UTC 的偏移量,±HH:mm | | ZZ | +0500 | UTC 的偏移量,±HHmm | | a | am/pm | | | A | AM/PM | | | AA | 上午/下午 | |