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

hongfangze-date

v1.1.0

Published

comm.date

Readme

日期操作类

介绍

一些日期的加减、格式化等函数

开始使用

npm install hongfangze-date

// import { foramt } from "hongfangze-date";
// import * as hfzarray from "hongfangze-date";

/**
 * 格式化时间
 * @param {string} [fmt] 格式,默认YYYY/MM/DD HH:mm:ss
 * @param {Date} [date] 需要格式化的时间,默认当前时间
 * @return {*}  {string}
 */
export declare const format: (fmt?: string, date?: Date) => string;
/**
 * 指定日期对应月份的第一天
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {Date}
 */
export declare const firstDateOfMonth: (date?: string | Date) => Date;
/**
 * 获取指定日期的当年第一天
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {Date}
 */
export declare const firstDateOfYear: (date?: string | Date) => Date;
/**
 * 指定日期对应月份的最后一天
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {Date}
 */
export declare const lastDateOfMonth: (date?: string | Date) => Date;
/**
 * 获取指定日期的当年最后一天
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {Date}
 */
export declare const lastDateOfYear: (date?: string | Date) => Date;
/**
 * 获得指定日期的所在周的周起止时间
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {string[]}
 */
export declare const currentWeek: (date?: string | Date) => string[];
/**
 * 获得指定日期所在月份的月的起止时间
 * @param {(string | Date)} [date] 指定日期,默认当前日期
 * @return {string[]}
 */
export declare const currentMonth: (date?: string | Date) => string[];
/**
 * 获取指定日期所在的季度的开始的月份
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date}
 */
export declare const quarterSeasonStartMonth: (date?: string | Date) => Date;
/**
 * 获取指定日期所在的季度的时间范围
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date}
 */
export declare const quarterSeason: (date?: string | Date) => Date[];
/**
 * 获取指定日期对应年月的月天数
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Number}
 */
export declare const monthDays: (date?: string | Date) => number;
/**
 * 返回指定日期上一个月的第一天
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date}
 */
export declare const priorMonthFirstDay: (date?: string | Date) => Date;
/**
 * 返回指定日期下一个月的第一天
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date}
 */
export declare const nextMonthFirstDay: (date?: string | Date) => Date;
/**
 * 获得指定日期的上一月的起止日期
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date[]}
 */
export declare const previousMonth: (date?: string | Date) => Date[];
/**
 * 获得指定日期的下一月的起止日期
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date[]}
 */
export declare const nextMonth: (date?: string | Date) => Date[];
/**
 * 获得指定日期上一周的起止日期
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date[]}
 */
export declare const previousWeek: (date?: string | Date) => Date[];
/**
 * 获得指定日期下一周的起止日期
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {string[]}
 */
export declare const nextWeek: (date?: string | Date) => string[];
/**
 * 得到指定日期上一年的起止日期
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date[]}
 */
export declare const previousYear: (date?: string | Date) => Date[];
/**
 * 得到指定日期下一年的起止日期
 * @param {(string | Date)} [date] 指定日期,默认当前时间
 * @return {Date[]}
 */
export declare const nextYear: (date?: string | Date) => Date[];
/**
 * 增加或减少指定的毫秒数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addMilliseconds: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的秒数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addSeconds: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的分钟数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addMinutes: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的小时数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addHours: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的天数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addDays: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的周数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addWeeks: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的月数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addMonths: (number: number, date?: string | Date) => Date;
/**
 * 增加或减少指定的年数
 * @param {number} number 需要增加或减少的具体数值,负数减少,正数增加,0不变
 * @param {(string | Date)} [date] 日期,默认当前时间
 * @return {Date}
 */
export declare const addYears: (number: number, date?: string | Date) => Date;

/**
 * 将指定格式的字符串转换成时间
 * - 如果格式中不存在某一个时刻,则返回当前时刻
 * - 如果格式或字符串错误,返回当前时间
 * @param {string} [date] 某一种格式的字符串形式
 * @param {string} [format] 格式:包含YYYY、MM/M、DD/D、HH/H、mm/m、ss/s的任意组合
 * - 可以但不限于以下几种格式(只要出现年月日时分秒几个关键字,可以自由组合,不支持毫秒和季度):
 * - YYYYMMDDHHmmss 对应的date传值如:20250702091234
 * - YYYYMDHHmmss 对应的date传值如:202572091234
 * - YYYY/MM/DD HH:mm:ss 对应的date传值如:2025/07/02 09:12:34
 * - YYYY-MM-DD HH:mm:ss 对应的date传值如:2025-07-02 09:12:34
 * - YYYY 对应的date传值如:2025
 * - YYYY/MM/DDHHmmss 对应的date传值如:2025/07/02091234
 * - ssmmHHDDMMYYYY 对应的date传值如:34120902072025
 * - MM/DD/YYYY 对应的date传值如:07/02/2025
 * @return {*}  {Date}
 */
export declare const toDate: (date?: string, format?: string) => Date;

版本迭代记录

2025-07-02 v1.1.0

  • 增加toDate函数。

2025-04-09 v1.0.1

  • 被移除后更名发布。
  • 完善注释。
  • format默认格式更改为“YYYY/MM/DD HH:mm:ss”防止ios端无法解析“YYYY-MM-DD”格式。