程序员程序园

SimplerDateFormat 一个更简单的SimpleDa

2019-04-26  本文已影响2人  Nawbc

SimplerDateFormat(pattern: string,[week: Array<string>])

SimplerDateFormat 是一个特别简单的时间格式化js包类似于java的SimplerDateFormat,但是它更加简单😜!

https://github.com/sewerganger/simpler-date-format

1. Api

构造函数

SimplerDateFormat(string, week)

方法

format(date: Date); // format time you want zone(number); // setZoneTime and format

日期用大写字母,时间用小写字母,字母是随机的,使用空格分隔,输入的顺序是输出的顺序。使用特殊符号(除~)表示一周中输出的日期。在句子前加~可反转输出;

2.举个🌰子


const SimplerDateFormat = require('simpler-date-format');

//定义一周
const weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' ,'Sunday'];

var sd = new SimplerDateFormat('Y/M/D h:m:d');
sd.format(new Date());              //2019/04/23 22:36:44

var sd = new SimplerDateFormat('Y$M$D h:m:d @');
sd.format(new Date());              //2019$04$23 22:36:44 2

var sd = new SimplerDateFormat('h:m:d Y/M/D');
sd.format(new Date());              //22:36:44 2019/04/23

//反转输出
var sd = new SimplerDateFormat('@ h:m:d ~Y/M/D', week); 
sd.format(new Date());              // Tuesday 22:36:44 04/23/2019

//北京时间并输出星期几 自行定义
var sd = new SimplerDateFormat('h:m:d ~Y/M/D', week);
sd.zone(8);              //22:36:44 04/23/2019 Tuesday 

还有更多的功能未开发,欢迎加入Muguet-ui开发交流,群聊号码:279499604

如果你喜欢可以 在gayhub❤

上一篇 下一篇

猜你喜欢

热点阅读