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

timedate.js

v1.1.0

Published

提供各种日期时间计算和转换的js插件

Readme

timedate.js

提供各种日期时间计算和转换的js插件

功能介绍

  • 计算两个时间之间的时间差
  • 时间转化为秒数
  • 日期格式化为yyyy-mm-dd hh:mm:ss || yyyy年mm月dd日
  • yyyy-mm-dd hh:mm:ss日期去除时分秒为yyyy-mm-dd
  • 计算两个日期相差天数
  • 获取当前日期的所有信息
  • 判断是否为闰年
  • 获取当前周的起始和结束日期
  • 校验时间字符串是否符合指定的格式
  • 其他功能待更新...

使用

安装

yarn add timedate.js

导入

import timedate from 'timedate'

具体API调用

  • 计算两个时间之间的时间差, getHour
let date1 = '2019-12-30 14:00:00' // *值不能为纯日期, 比如:2019-12-30
let date2 = '2020-01-01 14:00:00 ' // *值不能为纯日期, 比如:2020-01-01
timedate.getHour(date1, date2) // 得到相差的小时数
  • 获取一个时间的总秒数, transitionToSeconds
let time = '16:00:00' // *值不能为纯日期, 比如:2019-12-30
timedate.transitionToSeconds(time) // 得到总的秒数
  • 日期格式化, dateFormat
let date = new Date() // 值不能为纯时间,比如:10:45:30
timedate.dateFormat(date) // 得到一个对象,对象里包含yyyy-mm-dd hh:mm:ss & yyyy年mm月dd日 hh:mm:ss & yyyy-mm-dd hh:mm & yyyy-mm-dd & mm-dd & hh:mm:ss & h:m & yyyy年mm月dd日 & mm月dd日
  • 日期去除时分秒, removeHMS
let date = '2020-01-01 16:00:00'
timedate.removeHMS(date) // 得到'2020-01-01'
  • 返回两个日期相差的天数, dateDiff
let date1 = '2019-12-13' // 值不能为纯时间,比如:10:45:30
let date2 = '2019-12-15' // 值不能为纯时间,比如:10:45:30
timedate.dateDiff(date1, date2) // 得到一个对象,对象里包含两个属性: days(不含今天,如:2019-12-13到2019-12-15,相差两天)和daysCA(包含今天,如:2019-12-13到2019-12-15,相差三天天)
  • 获取一个日期的所有信息, getFormat
let date = new Date()
timedate.getFormat(date) // 得到一个对象,对象里包含:年,月,日,时,分,秒,星期,时间戳,当前毫秒数
  • 判断是否为闰年, isLeapYear
let date = '2020'
timedate.isLeapYear(date) // 得到true
  • 获取当前周的起始和结束日期, getCurrentWeekDates
timedate.getCurrentWeekDates() // 得到一个对象,对象包含当前周的起始日期:start,当前周的结束日期:end
  • 校验时间字符串是否符合指定的格式, validateTimeFormat
let date = '2019-12-13'
timeData.validateTimeFormat(date, 'YYYY-MM-DD') // 得到true