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 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-time.js

v1.3.14

Published

时间转换

Downloads

39

Readme

js-time

缩减 day.js, 增加 ie兼容,增加相距时间。

codecov Build Status

安装

npm install js-time.js --save

使用

import time from 'js-time.js';

time().format('YYYY-MM-DD HH:mm:ss'); // 2018-08-15 15:44:33

API

  • format

    time().format(); // 2018-08-15 15:44:33
    
    time().format('YYYY-MM-DD'); // 2018-08-15
    
    time(1534325803000).format('YYYY-MM-DD') // 2018-08-15
  • ago

    /*
    * 小于10秒
    * 刚刚
    */
    time('2018-8-1 1:0:0').ago('2018-8-1 0:59:51'); // 刚刚
    
    /*
    * 大于10秒,小于60秒
    * x 秒前
    */
    time('2018-8-1 1:0:0').ago('2018-8-1 0:59:30'); // 30秒前
    
    /*
    * 大于60秒,小于1小时
    * x 分钟前
    */
    time('2018-8-1 1:0:0').ago('2018-8-1 0:30:30'); // 29分钟前
    
    /*
    * 大于1小时,小于1天
    * x 小时前
    */
    time('2018-8-1 1:0:0').ago('2018-7-31 5:30:30'); // 19小时前
    
    /*
    * 大于1天,小于1个月
    * x 天前
    */
    time('2018-8-1 1:0:0').ago('2018-7-11 5:30:30'); // 20天前
    
    /*
    * 大于1个月,小于1年
    * x 个月前
    */
    time('2018-8-1 1:0:0').ago('2018-3-11 5:30:30'); // 4个月前
    
    /*
    * 大于1年
    * x 年前
    */
    time('2018-8-1 1:0:0').ago('2015-3-11 5:30:30'); // 3年前
  • isValid

    time('sss').isValid(); // false
    time().isValid(); // true
  • isSame

    time('2018-1-1').isSame('2018-1-1'); // true
  • isBefore

    time('2018-1-1').isBefore('2018-1-2'); // true
  • isAfter

    time('2018-1-1').isAfter('2018-1-2'); // false
  • year

    time().year(); // 2018
  • month

    time().month(); // 7
  • day

    time().day(); // 3
  • date

    time().date(); // 15
  • hour

    time().hour(); // 17
  • minute

    time().minute(); // 16
  • second

    time().second(); // 18
  • millisecond

    time().millisecond(); // 130
  • unix

    time().unix(); // 1534324615
  • valueOf

    time().unix(); // 1534324916443
  • toDate

    time().toDate(); // Wed Aug 15 2018 17:24:10 GMT+0800 (中国标准时间)
  • toObject

    time().toObject(); // ["years":2018,"months":7,"date":15,"hours":17,"minutes":23,"seconds":28,"milliseconds":623]
  • dayNum

    time('2018-8-20').dayNum('2018-8-19') // 1 (几天之前)
  • monthDays

    // 获取当月天数 无月份默认1月
    
    time('2018-8-20').monthDays() // 31 
    time('2018-2').monthDays() // 29
    time('2018').monthDays() // 31

License

MIT