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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kaze-ts-date-utils

v1.0.0

Published

A simple and flexible TypeScript date formatting library

Readme

ts-date-utils

A simple and flexible TypeScript date formatting utility.

轻量、简洁的 TypeScript 日期时间格式化工具,支持自定义模板格式,适用于各种 Node.js 和浏览器项目。


✨ 特性

  • 支持自定义格式(YYYY-MM-DD HH:mm:ss
  • 支持时间戳格式化
  • 支持当前时间快速获取
  • 支持字符串解析成 Date
  • TypeScript 全类型提示
  • 零依赖,超轻量

📦 安装

npm install ts-date-utils

或使用 yarn:

yarn add ts-date-utils



⸻

🚀 快速开始

import { formatDate, formatTimestamp, now, parseDateString, isValidDate } from 'ts-date-utils';

// 获取当前时间
console.log(now()); 
// => 2025-04-29 19:45:00

// 格式化时间戳
console.log(formatTimestamp(1714387200000, 'YYYY/MM/DD')); 
// => 2025/04/29

// 格式化 Date 对象
const date = new Date('2025-05-01T12:00:00');
console.log(formatDate(date, 'YYYY年MM月DD日 HH:mm')); 
// => 2025年05月01日 12:00

// 解析字符串为 Date 对象
const parsed = parseDateString('2025-05-01 12:00:00');
console.log(parsed.toISOString());

// 校验是否为合法 Date
console.log(isValidDate(new Date())); 
// => true
console.log(isValidDate('hello')); 
// => false



⸻

🛠️ API 文档

formatDate(date: Date, format?: string): string

格式化一个 Date 对象为指定字符串。
	•	date:要格式化的日期对象
	•	format:格式模板,默认 'YYYY-MM-DD HH:mm:ss'

支持的模板字段:

字段	含义
YYYY	年份
MM	月(两位数)
DD	日(两位数)
HH	小时(两位数)
mm	分钟(两位数)
ss	秒钟(两位数)



⸻

formatTimestamp(timestamp: number, format?: string): string

格式化时间戳(毫秒数)为指定格式。

⸻

now(format?: string): string

获取当前时间的格式化字符串。

⸻

parseDateString(dateString: string): Date

将日期字符串解析成 Date 对象。
支持格式如:2025-04-29 18:00:00,2025/04/29 等。

⸻

isValidDate(date: unknown): boolean

判断传入参数是否为有效的 Date 对象。