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

@s5ming/time

v1.0.9

Published

添加 timestampToTimeStr 方法

Downloads

15

Readme

关于time的一些工具

引入

import { getDay, getWeek, timestampToDate, dateToDateStr, timestampToDateStr } from '@s5ming/time'

使用说明

getDay

获取日期

var day = getDay(n)
    @params n : 偏移的天数,默认是0,获取的今天 
    day : 返回结果 格式是 {year:year,month:month,date:date}

getWeek

获取今天是周几

var week = getWeek(date)
    @params date : 获取星期的日期 格式是 {year:year,month:month,date:date},不填默认今天
    week : 返回结果 0-7的数字,0对应周日

timestampToDate

时间戳转换成日期json

var date = timestampToDate(timestamp)
    @params timestamp : 时间戳
    date : 返回结果 格式 {year:year,month:month,date:date,hour:hour,minute:minute,second:second}

dateToDateStr

日期json转换成日期字符串

var dateStr = dateToDateStr(date, split)
    @params date : 需要转换格式的日期 格式是 {year:year,month:month,date:date}
    @params split : 年月日之间的分隔符,不填写则默认'-'
    dateStr : 返回日期字符串 格式 year-month-date

timestampToDateStr

时间戳转换成日期字符串

var dateStr = timestampToDateStr(timestamp)
    @params timestamp : 时间戳
    @params split : 年月日之间的分隔符,不填写则默认'-'
    dateStr : 返回日期字符串 格式 year-month-date

timeStrToDateObj

时间字符串转换成Date对象

var date = timeStrToDateObj(time,split)
    @params time : 时间字符串,分隔符标准请在下个字符串定义,例如:"2019-08-24 4:25:26"
    @params split : json参数{
                    dateSplit:'-',  //年月日之间的分隔符,不填写则默认'-'
                    mSplit:' ',     //年月日与时间之间的分隔符,不填写则默认' '
                    timeSplit:':'   //时间之间的分隔符,不填写则默认':'
                }
    @result date Date的实例对象

timeStrToTimestamp

时间字符串转换成时间戳

var timestamp = timeStrToTimestamp(time,split)
    //不做详细解释,与上方法相同,只是返回的结果是个时间戳

timestampToTimeStr

时间戳转换成时间字符串

var timeStr = timestampToTimeStr(timestamp,split)
    //不做详细解释,上方法的逆向转换,split参数与上相同

milliToHours

毫秒数转换成事件的方法 例如 15131315格式 >> 10:00:00 格式

var time = milliToHours(mill)
    //参数是毫秒数, 返回值是 时:分:秒 格式