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

yg-moment

v1.0.6

Published

Parse, validate, manipulate, and display dates

Downloads

74

Readme

博客 | NPM地址 | git源码 | gitee源码

项目介绍

本项目用于时间格式化,涵盖部分时间格式化场景。具体可查看使用示例和使用帮助,有任何问题欢迎留言。

npm install yg-moment

import { dateFormat,getWeek } from 'yg-moment';

使用示例

<template>
  <div id="data-view">
    <h1>{{ time }}</h1>
    <h1>{{ week }}</h1>
    <h1>{{ beforeTime }}</h1>
  </div>
</template>

<script>
import { dateFormat, getWeek, beforeDateFormat } from "yg-moment";
export default {
  name: "YgMoment",
  data() {
    return {
      time: "",
      week: "",
      beforeTime: "",
    };
  },
  created() {
    this.init();
    setInterval(() => {
      this.init();
    }, 500);
  },
  methods: {
    /**
     * getWeek此函数用于获取当前日期或指定日期是星期几,并以中文形式返回。
     * 如果未提供时间戳,则使用当前周几。
     * 返回值为0-6,分别代表星期日到星期六。
     * @param {string} [timestamp] - 可选参数,表示要查询的时间戳。如果未提供,则使用当前时间。
     * @returns {string} 中文表示的星期几,例如"星期一"。
     */
    getWeek() {
      this.week = getWeek();
    },

    /**
     * beforeDateFormat此函数用于获取指定日期离当前时间间隔多久,并以中文形式返回。(1年前,1个月前,1周前,1天前,1小时前,1分钟前,刚刚。)
     * 如果未提供时间戳,返回undefined 页面不报错也不做任何显示。
     * 返回值为0-6,分别代表星期日到星期六。
     * @param {string} [timestamp] - 必传参数,表示要查询的时间戳 必须是当前时间之前的时间戳,否则会返回 刚刚。
     * @returns {string}返回【 1年前,1个月前,1周前,1天前,1小时前,1分钟前,刚刚】
     */
    beforeDateFormat() {
      // this.beforeTime = beforeDateFormat(new Date('2024-07-04 18:30:00').getTime());
      this.beforeTime = beforeDateFormat(new Date("2024-07-04").getTime());
    },

    /**
     * getTime此函数用于获取时间  格式默认返回:YYYY-mm-dd HH:MM:SS   年-月-日 时:分:秒
     * 如果未提供时间戳,返回当前时间。
     * @param {string} [format="YYYY-mm-dd HH:MM:SS"] - 必传参数,表示要格式化的时间格式
     * @param {string} [timestamp] - 可选参数,表示要查询的时间戳,不传则默认为当前时间戳
     * @returns {string}返回  年-月-日 时:分:秒
     */
    getTime() {
      //    this.time = dateFormat("YYYY-mm-dd");// 返回 2024-07-04
      this.time = dateFormat("YYYY-mm-dd HH:MM:SS"); // 返回 2024-07-04 18:30:00
    },
	
    init() {
      this.getTime();
      this.getWeek();
      this.beforeDateFormat();
    },
  },
};
</script>

<style scoped>
</style>

使用帮助

| yg-moment格式化时间 | 说明文档| 返回值 | --- | --- | --- | | 格式代码 | 说明 | 返回值例子| | M | 数字表示的月份,没有前导零| 1到12| |MM|数字表示的月份,有前导零|01到12| |MMM |三个字母缩写表示的月份 |Jan到Dec| | MMMM |月份,完整的文本格式 |January到December| | Q |季度 |1到4| | D |月份中的第几天,没有前导零 |1到31| | DD |月份中的第几天,有前导零 |01到31| | d |星期中的第几天,数字表示 |0到6,0表示周日,6表示周六| | ddd |三个字母表示星期中的第几天 |Sun到Sat| | dddd| 星期几,完整的星期文本 |从Sunday到Saturday| | w |年份中的第几周 |如42:表示第42周| | YYYY| 四位数字完整表示的年份 |如:2014 或 2000| | YY |两位数字表示的年份 |如:14 或 98| | A |大写的AM PM |AM PM| | a |小写的am pm |am pm| | HH |小时,24小时制,有前导零| 00到23| | H |小时,24小时制,无前导零| 0到23| | hh |小时,12小时制,有前导零| 00到12| | h |小时,12小时制,无前导零| 0到12| | m |没有前导零的分钟数| 0到59| | mm |有前导零的分钟数| 00到59| | s |没有前导零的秒数| 1到59| | ss |有前导零的描述| 01到59| | X |Unix时间戳| 1411572969|

一、引入yg-moment.js

1.Node.js方式引入 
(1)安装
npm install yg-moment  或者  yarn add yg-moment

(2)引入
import { dateFormat,getWeek } from 'yg-moment';