
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
这是一个jsDate函数库,提供对Date和DateTime的基础操作。
npm install jlocal
import {LocalDate,LocalDateTime,Period} from "jlocal";
基本操作
alert(LocalDate.of(2018,1,2).plusMonth(2).plusDay(22));
//alert 2018-03-24
//格式化
new LocalDateTime("2018-01-01 12:21:33").format("yyyy年MM月dd日");//默认为yyyy-MM-dd
JLocal采用ES6的语法编写,由三个类构成
一个LocalDate对象仅拥有年、月、日
let localDate;
localDate = new LocalDate(new Date())
localDate = new LocalDate(new Date().getTime())
localDate = new LocalDate("2017-03-22")
// 静态方法
localDate = LocalDate.of(2017,3,22)
这些操作会改变localDate对象
localDate.year = 1018
localDate.month = 11
localDate.day = 24
localDate.week = 1 //设置成本周的第一天
// 不管年月日赋值如何 都会正确的计算
这些函数会返回一个新的LocalDate对象,而不会改变现有的对象
localDate.plusDay(20) //往后20天
localDate.minusDay(10)//往后10天
localDate.plusMonth(2);
localDate.plusWeek(1);
localDate.plusYear(1);
//省略减法
直接加上一个周期
localDate.plus(Period.between(localDate,new LocalDate()))
localDate.minus(Period.between(localDate,new LocalDate()))
let n=1;
//获取本周的第n天 返回新的LocalDate
localDate.withDayOfWeek(n);
//更简单的 还有
localDate.firstDayOfWeek();
localDate.lastDayOfWeek();
//获取本月的第n天 返回新的LocalDate
localDate.withDayOfMonth(n);
localDate.firstDayOfMonth();
localDate.lastDayOfMonth();
//获取本年的第n天 返回新的LocalDate
localDate.withDayOfWeek(n);
localDate.firstDayOfYear();
localDate.lastDayOfYear();
//是否是闰年
localDate.isLeapYear();
//这个月有多少天
localDate.maxDayOfMonth();
//年
localDate.maxDayOfYear();
LocalDateTime 相对 LocalDate 来说,多了时分秒和毫秒
let localDateTime = new LocalDateTime(new Date());
localDateTime = new LocalDateTime("2017-01-10 11:22:33.444");
localDateTime = LocalDateTime.of(2018,1,3,17,12,5,999)
localDateTime = new LocalDateTime(localDate);//将LocalDate扩展成LocalDateTime
//当然localDateTime 也可以转换成LocalDate
localDate = localDateTime.toLocalDate();
localDateTime = new LocalDateTime(localDateTime.toLocalDate())
//注意: 这样不会保留时分秒,以及毫秒
LocalDateTime 继承了 LocalDate 的所有功能,当然也多出了对时分秒和毫秒的操作
let localDateTime = new LocalDateTime(new Date());
localDateTime.plusDay(1024).plusMilliseconds(1111).minusHours(3);
localDateTime.year = 2017;//改变了localDateTime 的年
localDateTime.hours += 1;//往后一小时
Period用于描述两个时间之间的差let period=Perioid.between(start,end)。
也可以方便计算时间LocalDate和LocalDateTime对象都可以使用plus(period)和minus(period)方法。
let period = Period.of(0,1,10,3);
alert(new LocalDateTime().plus(period));// 当前时间往后1月10天3小时
不同的时间单位描述
let period = Period.of(0,1,10,3);
period.getMonths() //相差多少个月 22
period.getDays() //相差多少天
//...
period.getMilliseconds()
//已上换算都是向下取整
例子
let a = new LocalDateTime("2017-02-01 12:00:00");
let b = new LocalDateTime("2016-02-08 13:00:00");
b.plus(Period.between(a,b)).equals(a);// return true
注意:period的总时间永远会大于0,如果要得知a和b的大小关系可以使用Period.between(a,b).isNegative?'a大':'b大;
是否等于Period.between(a,b).isEmpty。
如果您有任何建议或意见,请提issues
FAQs
js日期时间函数库,仿java8LocalDate的API设计
We found that jlocal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.