이 정도면 됐지, 자바스크립트 날짜 타임 라이브러리 Qrono
27306 단어 JavaScriptTypeScripttech
Qrono의 특징🎨
기타 라이브러리 시간대와 언어 환경에 대응하기 위해 코드 기반이 커지거나 사용이 복잡해진다.
Luxon 기반 설명가 바로 그 핵심이다.
All those things will make it less likely you ever need to work explicitly with time zones and may also save you plenty of other headaches.
기타 라이브러리 여름 시간의 시작, 끝을 자유자재로 처리할 수 없는 이른바'썸의 시간'.
기타 라이브러리 등
Moment.js
매우 광범위하게 사용되는 (defact 표준) 훌륭한 프로그램 라이브러리는 2020년에 유지보수 모델로 옮겨졌다.
정음판의 대상으로서 오류가 발생하기 쉬운 근본적인 문제입니다. 다음에 소개한 후발 날짜와 시간 라이브러리는 모두 변하기 쉬운 디자인입니다.
Luxon
Moment.js의 관리자가 만든 이세계적 풍부한 라이브러리입니다.세련되고 기능이 풍부하다.코드는 읽기 쉽다.
기본적으로 로컬 시간 처리애매한 시간을 엄격히 처리할 수 없다입니다.
그러나 문서에서 애매한 시간에 어떤 행동을 취할 것인지에 대해 다른 프로그램 라이브러리와 선을 그었다.
Day.js
최소 2KBMoment.js 호환 라이브러리를 표방합니다.GiitHub 별 수가 많아 공장 표준이 되고 있다.코드를 읽기 어렵다.
시간대와 언어 환경에 대응하기 때문에 코드 기반이 매우 커졌다(2021-1-22시 원본 파일 수량은 178). 그러나tree-shaking이 유효하면 유효 사이즈가 작아진다.
다만 기본적으로 설치된 기능도 상세해 플러그인을 발표할 때마다 번거롭다.
소화하지 못함대량의 이슈 상황에서 비교적 큰 버전 업그레이드를 진행할 계획이다.
오류를 발견했지만 Pull request를 실행하지 않았습니다.
date-fns
이름과 같이 200개 이상의 순수 함수 그룹이 JavaScript를 조작하는 Date 객체를 제공합니다.TypeScript로 구현된 tree-shoking은 유효합니다.
자바스크립트의 데이트 대상이 주인공이 되기 때문에 음소거, 월 0시부터 문제가 그대로 상속됐다.
The ECMA TC39 Temporal Proposal
향후 표준 ECMAScript가 될 수 있음® API 권장 사항.엄밀하고 웅장함java.time이 설치된 방법이 되었다.
Qrono 가져오기📥
브라우저
<script src="path/to/qrono.min.js"></script>
<!-- from UNPKG -->
<script src="https://unpkg.com/qrono/dist/qrono.min.js"></script>
Node.기다리다
npm install qrono
// as module
import { qrono } from 'qrono'
// or CommonJS
const { qrono } = require('qrono')
사용 예🚀
구조기
// now
qrono()
// from various type of arguments
qrono('2022-12-31') // => 2022-12-31T00:00:00.000Z
qrono(new Date())
// followings are same 2022-12-31T15:23:11.321Z
qrono('2022-12-31 15:23:11.321')
qrono(1672500191321)
qrono(2022, 12, 31, 15, 23, 11, 321)
qrono([2022, 12, 31, 15, 23, 11, 321])
qrono({ year: 2022, month: 12, day: 31, hour: 15, minute: 23, second: 11, millisecond: 321 })
액세스 장치
const time = qrono(2022, 12, 31, 15, 23, 11, 321)
time.year() // => 2022
time.month() // => 12
time.day() // => 31
time.hour() // => 15
time.minute() // => 23
time.second() // => 11
time.millisecond() // => 321
time.second(0) // => returns new Qrono instance
시간대
// UTC as default
qrono('2022-12-31 15:23:11.321').toString() // => "2022-12-31T15:23:11.321Z"
// set default to local time
qrono.asLocaltime()
qrono('2022-12-31 15:23:11.321').toString() // => "2022-12-31T15:23:11.321-04:00"
qrono('2022-12-31 15:23:11.321').asUtc().hour() // => 11 as UTC
qrono('2022-12-31 15:23:11.321').hour() // => 15 as local time
바꾸다
qrono('2000-01-01').numeric() // => 946,684,800,000 milliseconds from UNIX epoch
=== +qrono('2000-01-01') // => true
const time = qrono('2000-01-02 03:04:05.006')
time.toObject() // => { year: 2000, month: 1, day: 2, hour: 3, minute: 4, second: 5, millisecond: 6 }
time.toArray() // => [2000, 1, 2, 3, 4, 5, 6]
time.nativeDate() // => JavaScript native Date instance
계산하다
qrono('2000-01-01 01:00:00.000') - qrono('2000-01-01') // => 3,600,000 milliseconds = 1 hour
qrono('2000-01-01 01:00:00.000') < qrono('2000-01-01') // => false
qrono('2000-01-01').plus(7200000).minus(3600000) // => 2000-01-01T01:00:00.000Z
qrono('2000-01-01').minus({ hour: 1, minute: 30 }) // => 1999-12-31T22:30:00.000Z
const today = qrono()
const yesterday = today.minus({ day: 1 })
const tommorrow = today.plus({ day: 1 })
today.isBetween(yesterday, tommorrow) // => true
단축키
const time = qrono('2000-01-02 03:04:05.006')
time.startOfYear() // => 2000-01-01T00:00:00.000Z
time.startOfMonth() // => 2000-01-01T00:00:00.000Z
time.startOfDay() // => 2000-01-02T00:00:00.000Z
time.startOfHour() // => 2000-01-02T03:00:00.000Z
time.startOfMinute() // => 2000-01-02T03:04:00.000Z
time.startOfSecond() // => 2000-01-02T03:04:05.000Z
time.dayOfWeek() // => 7 === qrono.sunday
time.dayOfYear() // => 2
time.isLeapYear() // => true
time.daysInMonth() // => 31
time.daysInYear() // => 366
// ISO week number. See https://en.wikipedia.org/wiki/ISO_week_date
time.weeksInYear() // => 52
time.weekOfYear() // => 52
time.yearOfWeek() // => 1999
// Daylight saving time stuff that is meaningful in case of local time
const localtime = time.asLocaltime()
localtime.hasDstInYear()
localtime.isInDst()
localtime.isDstTransitionDay()
localtime.minutesInDay()
날짜 유형QronnoDate
qrono.date(...)
는 Qrono
와 기본적으로 같은 방법조를 가진 실례QronoDate
를 되돌려준다.qrono.date('2000-01-02').toString() // => "2000-01-02"
qrono('2000-01-02 23:04:05.006').toDate() // => QronoDate instance 2000-01-02
qrono.date('2000-01-02').numeric() // => 10958 days from UNIX epoch
최후
요구사항과 오류가 있다면Issue.
Reference
이 문제에 관하여(이 정도면 됐지, 자바스크립트 날짜 타임 라이브러리 Qrono), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/urin/articles/6ca9cf8174fd92텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)