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

mini-datetime-format

v0.1.3

Published

迷你日期时间格式化

Downloads

10

Readme

mini-datetime-format

前言

迷你时间格式化 - 代替 momentjs

示例(dateFormat)

可用于国内简单的时间格式化

入参1:date

| date | 描述 | | -------------------------------- | -------- | | new Date() | 时间对象 | | 1555941187435 | 时间戳 | | 2019 年 04 月 22 日 21:53:52.030 | 时间格式 | | 2019-4-22 21:53:52 | 时间格式 | | 2019/04/22 21:53:52.030 | 时间格式 |

入参2:fmt

| fmt | 结果 | 描述 | | ---- | ------------ | ---------------------------------------------------------------- | | yyyy | 2019 | 完整年份 | | yy | 19 | 后两位年份 | | M | 4 | 月份(1-12) | | MM | 04 | 月份(01-12) | | d | 22 | 日期(1-31) | | dd | 22 | 日期(01-31) | | H | 21 | 小时(24 小时制)(0-23) | | HH | 21 | 小时(24 小时制)(00-23) | | h | 9 | 小时(12 小时制)(0-12) | | hh | 09 | 小时(12 小时制)(00-12) | | m | 53 | 分钟(0-59) | | mm | 53 | 分钟(00-59) | | s | 52 | 秒钟(0-59) | | ss | 52 | 秒钟(00-59) | | e | Mon | 星期英文缩写 | | ee | Monday | 星期英文全拼 | | E | 一 | 星期 | | EE | 周一 | 星期 | | EEE | 星期一 | 星期 | | S | 30 | 毫秒(0-999,建议单独输出 number 时使用 | | SS | 030 | 毫秒(000-999,建议输出 string 时使用 | | a | am 或 pm | 上下午 | | A | AM 或 PM | 上下午 | | aa | 上 或 下 | 上下午 | | AA | 上午 或 下午 | 上下午 | | q | 1 | 季度(1-3 月返回 1,4-6 月返回 2,7-9 月返回 3,10-12 月返回 4) |

示例 2(timeFormat)

可用于倒计时,播放器时间,计算时间差等场景

入参1:time

| time | 描述 | | --------- | -------------------- | | 246121 | 秒(number 类型) | | '246121' | 秒(string 类型) | | '20:22:1' | 时间格式(时:分:秒) | | '28:22:1' | 时间格式(时:分:秒) 小时支持大于24 | | '42:1' | 时间格式(分:秒) | | '242:1' | 时间格式(分:秒) 分钟支持大于60 |

入参2:fmt

| fmt | 结果 | 描述 | | -------------------------- | -------------------------- | ------------------------------------------------------------------- | | d 天 h 小时 m 分钟 s 秒 | 2 天 20 小时 22 分钟 1 秒 | 时间格式(0 天 0 小时 0 分 0 秒 - 29 天 23 小时 59 分钟 59 秒) | | H:mm:ss | 68:22:01 | 0:00:00 -719:59:59)(H:将天转换成小时) | | H:m:s | 68:22:1 | 时间格式(0:0:0 -719:59:59)(H:将天转换成小时) | | H | 68 | 小时(H:将天,转成小时)(注意:只能单用H,不能使用HH) | | M | 4102 | 分钟(M:将天,小时转成分钟)(注意:只能单用M,不能使用MM) | | S | 246121 | 秒钟(S:将天,小时,分钟转成秒钟)(注意:只能单用S,不能使用SS) |

调用参考

/**
 * dateFormat 时间格式化
 * @param {Date/string/number} date eg:'1990年12月1','1990-12-1','1990/12/1',new Date(),时间戳
 * @param {string} fmt eg: yyyy/MM/dd,yyyy年M月d日 H:m:s,EEE,hh:mm:ss.SS a
 * @returns 根据fmt格式,字符串类型的日期时间
 */

/**
 * timeFormat 时间格式化
 * @param {number/string} time 单位秒 (大于0,小于30天转化的秒)
 * @param {string} fmt eg: hh:mm:ss H M S
 * @returns 根据fmt格式,字符串类型的时间
 */
import dateFormat,{timeFormat} from ‘@ali/tbdx-dateFormat’


return (
  <div>
    <p>当前时间:{dateFormat(new Date(),'yyyy/MM/dd HH:mm:ss')}</p>
    <p>倒计时:{timeFormat(24*60*60,'hh:mm:ss')}</p>
  </div>
)

更新

2019年06月10日14:03:53 es6 转换成 es5,解决小程序老的 ios 版本 bug

v1.1.0 2019年06月10日14:03:53

  1. 增加单元测试,
  2. 时间转化小时支持大于24,分钟支持大于60
  3. 日期转化 e 输出 星期英文单词缩写,ee 输出星期英文单词全拼