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

cc-timetools

v1.2.7

Published

格式化时间,时间比较、计算、获取,html转义和还原,修复上个版本部分方法使用问题

Downloads

33

Readme

cc-timetools

提供各种日期时间计算和比较的js插件 使用require导入,import { ccTools } from 'timetools-new' 前往timetools-new

功能介绍

  • 格式化时间
  • 时间戳比较
  • 日期比较
  • 比较日期、时间戳是否同年
  • 比较日期、时间戳是否同月
  • 比较日期、时间戳是否同周
  • 增加时间(年/月/周/日/时/分/秒)
  • 减少时间(年/月/周/日/时/分/秒)
  • 获取时间的某个部分(年/月/周/日/时/分/秒)
  • 转义HTML
  • 还原HTML
  • 其他功能待更新...

使用

安装

npm install cc-timetools

导入

const ccMethod = require('cc-timetools')

功能说明

| 方法 | 描述 | 固定参数 | 处理参数类型 | | ---- | ---- | ---- | ---- | | dateFormat | 格式化时间 | | Date对象、时间戳| | compareTimestamps | 时间戳比较 | | 时间戳 | | compareDateStrings | 日期比较 | | 日期字符串 | | isSameYear | 比较日期、时间戳是否同年 | | Date对象、时间戳、日期字符串 | | isSameMonth | 比较日期、时间戳是否同月 | | Date对象、时间戳、日期字符串 | | isSameWeek | 比较日期、时间戳是否同周 | | Date对象、时间戳、日期字符串 | | addTime | 增加时间 | years, months, weeks, days, hours, minutes, seconds | Date对象、时间戳、日期字符串 | | subtractTime | 减少时间 | years, months, weeks, days, hours, minutes, seconds | Date对象、时间戳、日期字符串 | | getTimePart | 获取时间的某个部分 | year, month, weekday, date, hours, minutes, seconds | Date对象、时间戳、日期字符串 | | htmlEscape | 转义HTML | | | | htmlUnEscape | 还原HTML | | |

具体API调用

  • dateFormat格式化时间
//调用dateFormat对时间进行格式化
const dtStr = ccMethod.dateFormat(new Date())
console.log(dtStr);
  • compareTimestamps时间戳比较
// compareTimestamps时间戳比较
const dtStr = ccMethod.compareTimestamps(时间戳1,时间戳2)
console.log(dtStr);// 输出-1: time1 < time2; 输出1: time2 < time1; 输出0: time1 = time2
  • compareDateStrings日期string比较
// compareDateStrings日期string比较
const dtStr = ccMethod.compareDateStrings(日期1,日期2)
console.log(dtStr);// 输出-1: time1 < time2; 输出1: time2 < time1; 输出0: time1 = time2
  • isSameYear是否同一年
const dtStr = ccMethod.isSameYear(time1,time2)
console.log(dtStr);
  • isSameMonth是否同一月
const dtStr = ccMethod.isSameMonth(time1,time2)
console.log(dtStr);
  • isSameWeek是否同一周
const dtStr = ccMethod.isSameWeek(time1,time2)
console.log(dtStr);
  • 增加减少时间
// datetime原本时间, method使用固定参数string类型例如:'days'天,time增加时间number类型
const dtStr = ccMethod.addTime(datetime, method, time)
console.log(dtStr);
const dt1Str = ccMethod.subtractTime(datetime, method, time)
console.log(dt1Str)
  • 获取时间某个部分
// time原本时间,method使用固定参数string类型例如:'year'年
const dtStr = ccMethod.getTimePart(time, method)
console.log(dtStr);
  • 转义html中的特殊字符
//调用htmlEscape进行转换
const htmlStr = '<h1>这是h1标签<span>123&nbsp;</span></h1>'
console.log(ccMethod.htmlEscape(htmlStr));
  • 还原html中的特殊字符
//调用htmlUnEscape进行还原
const str = '&lt;h1&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
console.log(ccMethod.htmlUnEscape(str));

开源协议

ISC