이 정도면 됐지, 자바스크립트 날짜 타임 라이브러리 Qrono

했어.
https://github.com/urin/qrono#qrono----just-right-date-time-library

Qrono의 특징🎨

  • 시간대와 언어 환경에 대응하는 경미한 날짜 시간 라이브러리를 버렸다.

  • 기타 라이브러리 시간대와 언어 환경에 대응하기 위해 코드 기반이 커지거나 사용이 복잡해진다.
  • 로켈 전용 ECMAScript® Internationalization API
  • 대부분의 경우 클라이언트 환경의 표준 시간대에만 해당하면 충분합니다.
    Luxon 기반 설명가 바로 그 핵심이다.
  • Don't make servers think about local times. Configure them to use UTC and write your server's code to work in UTC. Times can often be thought of as a simple count of epoch milliseconds; what you would call that time (e.g. 9:30) in what zone doesn't (again, often) matter.
  • Communicate times between systems in ISO 8601, like 2017-05-15T13:30:34Z where possible (it doesn't matter if you use Z or some local offset; the point is that it precisely identifies the millisecond on the global timeline).
  • Where possible, only think of time zones as a formatting concern; your application ideally never knows that the time it's working with is called "9:00"until it's being rendered to the user.
  • Barring 3, do as much manipulation of the time (say, adding an hour to the current time) in the client code that's already running in the time zone where the results will matter.
    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.
  • 기본적으로 시간은 UTC로 처리됩니다.
  • 기본값을 로컬 시간으로 전환할 수도 있습니다.
  • 여름철을 엄격히 처리한다.

  • 기타 라이브러리 여름 시간의 시작, 끝을 자유자재로 처리할 수 없는 이른바'썸의 시간'.
  • 여름철을 엄격하게 처리하는 것은 여러 시간대의 대응을 버려야만 가능한 기술이다.
  • 기타 라이브러리 등


    Moment.js


    https://github.com/moment/moment
    매우 광범위하게 사용되는 (defact 표준) 훌륭한 프로그램 라이브러리는 2020년에 유지보수 모델로 옮겨졌다.
    정음판의 대상으로서 오류가 발생하기 쉬운 근본적인 문제입니다. 다음에 소개한 후발 날짜와 시간 라이브러리는 모두 변하기 쉬운 디자인입니다.

    Luxon


    https://github.com/moment/luxon
    Moment.js의 관리자가 만든 이세계적 풍부한 라이브러리입니다.세련되고 기능이 풍부하다.코드는 읽기 쉽다.
    기본적으로 로컬 시간 처리애매한 시간을 엄격히 처리할 수 없다입니다.
    그러나 문서에서 애매한 시간에 어떤 행동을 취할 것인지에 대해 다른 프로그램 라이브러리와 선을 그었다.

    Day.js


    https://github.com/iamkun/dayjs
    최소 2KBMoment.js 호환 라이브러리를 표방합니다.GiitHub 별 수가 많아 공장 표준이 되고 있다.코드를 읽기 어렵다.
    시간대와 언어 환경에 대응하기 때문에 코드 기반이 매우 커졌다(2021-1-22시 원본 파일 수량은 178). 그러나tree-shaking이 유효하면 유효 사이즈가 작아진다.
    다만 기본적으로 설치된 기능도 상세해 플러그인을 발표할 때마다 번거롭다.
    소화하지 못함대량의 이슈 상황에서 비교적 큰 버전 업그레이드를 진행할 계획이다.
    오류를 발견했지만 Pull request를 실행하지 않았습니다.

    date-fns


    https://github.com/date-fns/date-fns
    이름과 같이 200개 이상의 순수 함수 그룹이 JavaScript를 조작하는 Date 객체를 제공합니다.TypeScript로 구현된 tree-shoking은 유효합니다.
    자바스크립트의 데이트 대상이 주인공이 되기 때문에 음소거, 월 0시부터 문제가 그대로 상속됐다.

    The ECMA TC39 Temporal Proposal


    https://tc39.es/proposal-temporal/docs/index.html
    향후 표준 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.

    좋은 웹페이지 즐겨찾기