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

@jsany/date

v1.0.6

Published

javascript date small es5 es6+

Downloads

2

Readme

javascript date small es5 es6+

🏠 Homepage

🚀 Install

npm install --save-dev @jsany/date

Usage

import { dateFormat, UTCTimestamp, UTC2Target, Target2UTC } from '@jsany/date';

// or const { dateFormat, UTCTimestamp, UTC2Target, Target2UTC } = require('@jsany/date');

const dateStr = '2019-01-02 14:08:59';
const bj = '2019-01-01 08:00:00';
const ist = '2019-01-01 05:30:00';
const utc = '2019-01-01 00:00:00';
const utc_unix = 1546300800000;

/**
 * @description dateFormat:格式化日期
 * @param {(object|string)} date - 日期对象/字符串
 * @param {string} mask - 日期格式,默认:mask='yyyy-MM-dd HH:mm:ss'
 * @returns {string} 返回格式化后的日期
 */
dateFormat(dateStr, 'd'); // "2"
dateFormat(dateStr, 'dd'); // "02"
dateFormat(dateStr, 'ddd'); // "Wed"
dateFormat(dateStr, 'dddd'); // "Wednesday"
dateFormat(dateStr, 'M'); // "1"
dateFormat(dateStr, 'MM'); // "01"
dateFormat(dateStr, 'MMM'); // "Jan"
dateFormat(dateStr, 'MMMM'); // "January"
dateFormat(dateStr, 'yy'); // "19"
dateFormat(dateStr, 'yyyy'); // "2019"
dateFormat(dateStr, 'h'); // "2"
dateFormat(dateStr, 'hh'); // "02"
dateFormat(dateStr, 'H'); // "14"
dateFormat(dateStr, 'HH'); // "14"
dateFormat(dateStr, 'm'); // "8"
dateFormat(dateStr, 'mm'); // "08"
dateFormat(dateStr, 's'); // "59"
dateFormat(dateStr, 'ss'); // "59"
dateFormat(dateStr, 'l'); // "000"
dateFormat(dateStr, 'L'); // "00"
dateFormat(dateStr, 'tt'); // "pm"
dateFormat(dateStr, 'TT'); // "PM"
dateFormat(dateStr, 'Z'); // "GMT"
dateFormat(dateStr, 'yyyy/MM/dd HH:mm:ss'); // "2019/01/02 14:08:59"

=============================================

/**
 * @description UTCTimestamp:获取utc时间戳
 * @param {string} date - utc日期对象/字符串,默认:当前时间
 * @returns {number} 返回utc时间戳
 */
console.log(UTCTimestamp(utc), utc_unix);

=============================================

/**
 * @description UTC2Target:utc时间转目标时区的时间,默认为utc时间转本地时间
 * @param {object|string} date - utc时间,日期对象/字符串
 * @param {number} timezone - 目标时区,默认:本地时区timezone=-480(中国时区+0800)
 * @param {*} mask - 日期格式,默认:mask='yyyy-MM-dd HH:mm:ss'
 * @returns {string} 返回目标时区的时间
 */
// utc转北京时间(-480)
UTC2Target(utc, -480); // "2019-01-01 08:00:00"
// utc转印度时间(-330)
UTC2Target(utc, -330); // "2019-01-01 05:30:00"

=============================================

/**
 * @description Target2UTC:目标时区的时间转utc时间,默认为本地时间转utc时间
 * @param {object|string} date - 目标时区时间,日期对象/字符串
 * @param {number} timezone - 目标时区,默认:本地时区timezone=-480(中国时区+0800)
 * @param {*} mask - 日期格式,默认:mask='yyyy-MM-dd HH:mm:ss'
 * @returns {string} 返回目标时区的utc时间
 */
// 北京时间转utc(-480)
Target2UTC(bj, -480); // "2019-01-01 00:00:00"
// 印度时间转utc(-330)
Target2UTC(ist, -330); // "2019-01-01 00:00:00"

Run tests

npm run test

👀 View online

view

Author

👤 jzg

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2019 jzg. This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator