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

format-time-date

v1.0.4

Published

格式化日期时间

Downloads

5

Readme

Introduction

  • 格式化时间,能够将时间格式化成自己需要的样式,示例如下:
1、2018年05月16日 15时07分26秒 星期三
2、2018年05月16日 下午03时07分26秒 星期三
3、2018/05/16 15:07:26 星期三
4、2018-05-16 下午03时07分26秒
5、2018/05/16; 15:07:26; 星期三
6、2018年05月16日
7、2018/05/16  // 当只要返回时间是,也可以利用new Date().toLocaleDateString()方法,注意兼容性
8、15时07分26秒
9、星期三
10、etc...
  • 原生的toLocaleString暂时还不完善,如去掉月份保留日或者去掉分钟保留秒,返回的是乱值,而且还有兼容问题,暂不考虑;
new Date().toLocaleString('chinese', {
    hour12: false,
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit"
})

Usage

const formatTime = require('format-time-date');

let date = formatTime();

console.log(date);

Options

{
    // 设置日期时间,默认为当前日期时间,如果要设置为某一个时间,可以类似:new Date('2020/06/04 20:1:23')
    date: new Date(),
    // 是否为24小时制,为false时代表为12小时制
    isHour24: true,
    // 单位,分别代表:年、月、日、时、分、秒的单位;
    unit: ['年', '月', '日', '时', '分', '秒'],
    // 分隔符,第一个是日期与时间之间的风格符,第二个是时间与星期之间的分隔符
    seperator: [' ', ' '],
    // 是否显示年
    isYear: true,
    // 是否显示月
    isMonth: true,
    // 是否显示日
    isDay: true,
    // 是否显示时
    isHours: true,
    // 是否显示分
    isMinute: true,
    // 是否显示秒
    isSecond: true,
    // 是否显示星期
    isWeekday: true
}