{"id":13394242,"url":"https://github.com/you-dont-need/You-Dont-Need-Momentjs","last_synced_at":"2025-03-13T20:31:21.887Z","repository":{"id":37759356,"uuid":"147943107","full_name":"you-dont-need/You-Dont-Need-Momentjs","owner":"you-dont-need","description":"List of functions which you can use to replace moment.js + ESLint Plugin","archived":false,"fork":false,"pushed_at":"2023-12-01T10:45:12.000Z","size":961,"stargazers_count":13280,"open_issues_count":30,"forks_count":319,"subscribers_count":139,"default_branch":"master","last_synced_at":"2024-10-29T11:24:49.641Z","etag":null,"topics":["bundle-size","date-fns","esmodules","hacktoberfest","moment-js","pure-function","tree-shaking"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/you-dont-need.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-08T14:57:38.000Z","updated_at":"2024-10-27T16:19:17.000Z","dependencies_parsed_at":"2024-02-04T16:20:02.032Z","dependency_job_id":"a7995e54-800c-4d44-be57-bd9d3884ed44","html_url":"https://github.com/you-dont-need/You-Dont-Need-Momentjs","commit_stats":{"total_commits":175,"total_committers":43,"mean_commits":4.069767441860465,"dds":0.8,"last_synced_commit":"cddf08294c43ed04802eec0ce1afc0d835310911"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/you-dont-need%2FYou-Dont-Need-Momentjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/you-dont-need%2FYou-Dont-Need-Momentjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/you-dont-need%2FYou-Dont-Need-Momentjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/you-dont-need%2FYou-Dont-Need-Momentjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/you-dont-need","download_url":"https://codeload.github.com/you-dont-need/You-Dont-Need-Momentjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243478059,"owners_count":20297186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle-size","date-fns","esmodules","hacktoberfest","moment-js","pure-function","tree-shaking"],"created_at":"2024-07-30T17:01:13.579Z","updated_at":"2025-03-13T20:31:21.865Z","avatar_url":"https://github.com/you-dont-need.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","HarmonyOS","Content","Articles","目录","前端开发框架及项目","Learning Resources","Bundle size optimization guides"],"sub_categories":["Windows Manager","其他_文本生成、文本对话","General","You Don't Need X"],"readme":"# [You don't (may not) need Moment.js](https://you-dont-need.github.io/You-Dont-Need-Momentjs/#/)\n\n[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://dev.to/t/momentjs)\n\n[Moment.js](https://momentjs.com/) is a fantastic time \u0026 date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size.\n\n![Large bundle size](./screenshot.png)\n\nProblems with Moment.js:\n\n- It is highly based on OOP APIs, which makes it fail to work with tree-shaking, thus leading to a huge bundle size and performance issues.\n- It is mutable and it causes bugs:\n  - [clone](https://momentjs.com/docs/#/parsing/moment-clone/)\n  - [How do I work around mutability in moment.js?](https://stackoverflow.com/questions/30979178/how-do-i-work-around-mutability-in-moment-js)\n- Complex OOP API (which doubles mutability problem). Here is an example:\n  https://github.com/moment/moment/blob/develop/src/test/moment/add_subtract.js#L244-L286\n  Moment.js allows to use `a.subtract('ms', 50)`, `a.subtract(50, 'ms')` and even `a.subtract('s', '50')`.\n\nIf you are not using timezone but only a few simple functions from moment.js, this might bloat your app, and therefore is considered overkill. [dayjs](https://github.com/iamkun/dayjs) has a smaller core and has very similar APIs so it makes it very easy to migrate. [date-fns](https://github.com/date-fns/date-fns) enables [tree-shaking and other benefits](https://github.com/date-fns/date-fns/issues/275#issuecomment-264934189) so that it works great with React, Sinon.js, and webpack, etc. See https://github.com/moment/moment/issues/2373 for more ideas on why and how people switch from moment.js to other solutions.\n\n## Brief Comparison\n\n| Name      | Tree-shaking | Methods richness | Pattern    | Locale | Timezone Support       | Popularity (stars)                                               | Sizes                                                                                                                        |\n| --------- | ------------ | ---------------- | ---------- | ------ | ---------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |\n| Moment.js | No           | High             | OO         | 123    | Good (moment-timezone) | ![stars](https://flat.badgen.net/github/stars/moment/moment)     | ![raw](https://flat.badgen.net/bundlephobia/min/moment?label=min) ![size](https://flat.badgen.net/bundlephobia/minzip/moment?label=zip\u0026color=purple)     |\n| Luxon     | No           | High             | OO         | -      | Good (Intl)            | ![stars](https://flat.badgen.net/github/stars/moment/luxon)      | ![raw](https://flat.badgen.net/bundlephobia/min/luxon?label=min) ![size](https://flat.badgen.net/bundlephobia/minzip/luxon?label=zip\u0026color=purple)       |\n| date-fns  | Yes          | High             | Functional | 64     | Good (date-fns-tz)     | ![stars](https://flat.badgen.net/github/stars/date-fns/date-fns) | ![raw](https://flat.badgen.net/bundlephobia/min/date-fns?label=min) ![size](https://flat.badgen.net/bundlephobia/minzip/date-fns?label=zip\u0026color=purple) |\n| dayjs     | No           | High             | OO         | 138    | Good (Intl)            | ![stars](https://flat.badgen.net/github/stars/iamkun/dayjs)      | ![raw](https://flat.badgen.net/bundlephobia/min/dayjs?label=min) ![size](https://flat.badgen.net/bundlephobia/minzip/dayjs?label=zip\u0026color=purple)       |\n\n## Voice of Developers\n\n\u003e [Removed moment.js to replace with date-fns - build output reduced by 40%](https://github.com/oysterprotocol/webnode/pull/116)\n\n\u003e \u0026mdash;\u003ccite\u003eJared Farago from [webnode](https://github.com/oysterprotocol/webnode/pull/116) project.\u003c/cite\u003e\n\n\u003e [Good library if you’re looking to replace Moment.js for one reason or another. Immutable too.](https://twitter.com/dan_abramov/status/805030922785525760)\n\n\u003e \u0026mdash;\u003ccite\u003eDan Abramov, Author of [Redux](https://github.com/reduxjs/redux) and co-author of [Create React App](https://github.com/facebook/create-react-app). Building tools for humans.\u003c/cite\u003e\n\n\u003e [I strongly recommend using date-fns over Moment.js, it's has a nicer API and you can include only parts you need!](https://twitter.com/silvenon/status/804946772690923520)\n\n\u003e \u0026mdash;\u003ccite\u003eMatija Marohnić, a design-savvy frontend developer from Croatia.\u003c/cite\u003e\n\n## ESLint Plugin\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/eslint-plugin-you-dont-need-momentjs\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/eslint-plugin-you-dont-need-momentjs.svg?style=flat-square\"\n      alt=\"NPM Version\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/eslint-plugin-you-dont-need-momentjs\"\u003e\n    \u003cimg src=\"http://img.shields.io/npm/dm/eslint-plugin-you-dont-need-momentjs.svg?style=flat-square?style=flat-square\"\n      alt=\"Downloads\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/you-dont-need/You-Dont-Need-Momentjs\"\u003e\n    \u003cimg src=\"https://img.shields.io/travis/you-dont-need/You-Dont-Need-Momentjs/master.svg?style=flat-square\"\n      alt=\"Build Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/you-dont-need/You-Dont-Need-Momentjs?branch=master\"\u003e\n    \u003cimg src=\"https://img.shields.io/coveralls/you-dont-need/You-Dont-Need-Momentjs/master.svg?style=flat-square\"\n      alt=\"Coverage Status\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nIf you're using [ESLint](http://eslint.org/), you can install a\n[plugin](http://eslint.org/docs/user-guide/configuring#using-the-configuration-from-a-plugin) that\nwill help you identify places in your codebase where you don't (may not) need Moment.js.\n\nInstall the plugin...\n\n```sh\nnpm install --save-dev eslint-plugin-you-dont-need-momentjs\n```\n\n...then update your config\n\n```js\n\"extends\" : [\"plugin:you-dont-need-momentjs/recommended\"],\n```\n\n## Quick Links\n\n**[Parse](#parse)**\n\n1. [String + Date Format](#string--date-format)\n1. [String + Time Format](#string--time-format)\n1. [String + Format + locale](#string--format--locale)\n\n**[Get + Set](#get--set)**\n\n1. [Millisecond/Second/Minute/Hour](#millisecond--second--minute--hour)\n1. [Date of Month](#date-of-month)\n1. [Day of Week](#day-of-week)\n1. [Day of Year](#day-of-year)\n1. [Week of Year](#week-of-year)\n1. [Days in Month](#days-in-month)\n1. [Weeks in Year](#weeks-in-year)\n1. [Maximum of the given dates](#maximum-of-the-given-dates)\n1. [Minimum of the given dates](#minimum-of-the-given-dates)\n\n**[Manipulate](#manipulate)**\n\n1. [Add](#add)\n1. [Subtract](#subtract)\n1. [Start of Time](#start-of-time)\n1. [End of Time](#end-of-time)\n\n**[Display](#display)**\n\n1. [Format](#format)\n1. [Time from now](#time-from-now)\n1. [Time from X](#time-from-x)\n1. [Difference](#difference)\n\n**[Query](#query)**\n\n1. [Is Before](#is-before)\n1. [Is Same](#is-same)\n1. [Is After](#is-after)\n1. [Is Between](#is-between)\n1. [Is Leap Year](#is-leap-year)\n1. [Is a Date](#is-a-date)\n\n# Feature Parity\n\n⚠️ Indicates other packages or work are needed. See individual functions [above](#quick-links).\n\n|                                | Native | Luxon | date-fns | dayjs | Temporal |\n| ------------------------------ | ------ | ----- | -------- | ----- | -------- |\n| **Parse**                      |        |       |          |       |          |\n| String + Date Format           | ✅     | ✅     | ✅       | ✅    | ✅         |\n| String + Time Format           | ✅     | ✅     | ✅       | ⚠️    | ✅        |\n| String + Format + locale       | ❌     | ⚠️     | ✅       | ⚠️    | ❌        |\n|                                |        |       |          |       |          |\n| **Get + Set**                  |        |       |          |       |          |\n| Millisecond/Second/Minute/Hour | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Date of Month                  | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Day of Week                    | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Day of Year                    | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Week of Year                   | ✅     | ✅    | ✅       | ⚠️    | ✅        |\n| Days in Month                  | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Weeks in Year                  | ❌     | ❌    | ✅       | ⚠️    | ✅        |\n| Maximum of the given dates     | ✅     | ✅    | ✅       | ⚠️    | ✅        |\n| Minimum of the given dates     | ✅     | ✅    | ✅       | ⚠️    | ✅        |\n|                                |        |       |          |       |          |\n| **Manipulate**                 |        |       |          |       |          |\n| Add                            | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Subtract                       | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Start of Time                  | ❌     | ✅    | ✅       | ✅    | ✅        |\n| End of Time                    | ✅     | ✅    | ✅       | ✅    | ✅        |\n|                                |        |       |          |       |          |\n| **Display**                    |        |       |          |       |          |\n| Format                         | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Time from now                  | ✅     | ❌    | ✅       | ⚠️    | ✅        |\n| Time from X                    | ❌     | ❌    | ✅       | ⚠️    | ✅        |\n| Difference                     | ✅     | ✅    | ✅       | ✅    | ✅        |\n|                                |        |       |          |       |          |\n| **Query**                      |        |       |          |       |          |\n| Is Before                      | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Is Same                        | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Is After                       | ✅     | ✅    | ✅       | ✅    | ✅        |\n| Is Between                     | ❌     | ✅    | ✅       | ⚠️    | ❌        |\n| Is Leap Year                   | ✅     | ✅    | ✅       | ⚠️    | ✅        |\n| Is a Date                      | ✅     | ✅    | ✅       | ✅    | ✅        |\n\n## Parse\n\n### String + Date Format\n\nReturn the date parsed from date string using the given format string.\n\n```js\n// Moment.js\nmoment('12-25-1995', 'MM-DD-YYYY');\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n\n// Native\nconst datePattern = /^(\\d{2})-(\\d{2})-(\\d{4})$/;\nconst [, month, day, year] = datePattern.exec('12-25-1995');\nnew Date(`${month}, ${day} ${year}`);\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n\n// date-fns\nimport parse from 'date-fns/parse';\nparse('12-25-1995', 'MM-dd-yyyy', new Date());\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n\n// dayjs\ndayjs('12-25-1995');\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n\n// luxon\nDateTime.fromFormat('12-25-1995', 'MM-dd-yyyy').toJSDate();\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n\n// Temporal\nconst datePattern = /^(\\d{2})-(\\d{2})-(\\d{4})$/;\nconst [, month, day, year] = datePattern.exec('12-25-1995');\nnew Temporal.ZonedDateTime.from({year, month, day, timeZone: Temporal.Now.timeZone()});\n// =\u003e \"1995-12-24T13:00:00.000Z\"\n```\n\n**[⬆ back to top](#quick-links)**\n\n### String + Time Format\n\nReturn the date parsed from time string using the given format string.\n\n```js\n// Moment.js\nmoment('2010-10-20 4:30', 'YYYY-MM-DD HH:mm');\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n\n// Native\nconst datePattern = /^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{1,2}):(\\d{2})$/;\nconst [, year, month, day, rawHour, min] = datePattern.exec('2010-10-20 4:30');\nnew Date(`${year}-${month}-${day}T${('0' + rawHour).slice(-2)}:${min}:00`);\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n\n// date-fns\nimport parse from 'date-fns/parse';\nparse('2010-10-20 4:30', 'yyyy-MM-dd H:mm', new Date());\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n\n// dayjs ⚠️ requires customParseFormat plugin\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\ndayjs.extend(customParseFormat);\ndayjs('2010-10-20 4:30', 'YYYY-MM-DD HH:mm');\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n\n// luxon\nDateTime.fromFormat('2010-10-20 4:30', 'yyyy-MM-dd H:mm').toJSDate();\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n\n// Temporal\nconst datePattern = /^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{1,2}):(\\d{2})$/;\nconst [, year, month, day, hour, minute] = datePattern.exec('2010-10-20 4:30');\nnew Temporal.ZonedDateTime.from({year, month, day, hour, minute, timeZone: Temporal.Now.timeZone()});\n// =\u003e \"2010-10-19T17:30:00.000Z\"\n```\n\n**[⬆ back to top](#quick-links)**\n\n### String + Format + locale\n\nReturn the date parsed from string using the given format string and locale.\n\n```js\n// Moment.js\nmoment('2012 mars', 'YYYY MMM', 'fr');\n// =\u003e \"2012-02-29T13:00:00.000Z\"\n\n// date-fns\nimport parse from 'date-fns/parse';\nimport fr from 'date-fns/locale/fr';\nparse('2012 mars', 'yyyy MMMM', new Date(), { locale: fr });\n// =\u003e \"2012-02-29T13:00:00.000Z\"\n\n// dayjs ⚠️ requires customParseFormat plugin\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport 'dayjs/locale/fr';\ndayjs.extend(customParseFormat);\ndayjs('2012 mars', 'YYYY MMM', 'fr');\n// =\u003e \"2012-02-29T13:00:00.000Z\"\n\n// Luxon ❌ does not support Locale for node unless https://moment.github.io/luxon/docs/manual/install.html#node\nDateTime.fromFormat('2012 mars', 'yyyy MMMM', { locale: 'fr' });\n// =\u003e \"2012-02-29T13:00:00.000Z\"\n```\n\n**[⬆ back to top](#quick-links)**\n\n## Get + Set\n\n### Millisecond / Second / Minute / Hour\n\nGet the `Millisecond/Second/Minute/Hour` of the given date.\n\n```js\n// Moment.js\nmoment().seconds();\n// =\u003e 49\nmoment().hours();\n// =\u003e 19\n\n// Native\nnew Date().getSeconds();\n// =\u003e 49\nnew Date().getHours();\n// =\u003e 19\n\n// date-fns\nimport getSeconds from 'date-fns/getSeconds';\nimport getHours from 'date-fns/getHours';\ngetSeconds(new Date());\n// =\u003e 49\ngetHours(new Date());\n// =\u003e 19\n\n// dayjs\ndayjs().second();\n// =\u003e 49\ndayjs().hour();\n// =\u003e 19\n\n// Luxon\nDateTime.local().second;\n// =\u003e 49\nDateTime.local().hour;\n// =\u003e 19\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().second;\n// =\u003e 49\nTemporal.Now.zonedDateTimeISO().hour;\n// =\u003e 19\n```\n\n### Performance tests\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1500.703ms |\n| Native   | 348.411ms  |\n| DateFns  | 520.670ms  |\n| DayJs    | 494.234ms  |\n| Luxon    | 1208.368ms |\n| Temporal | -          |\n\nSet the `Millisecond/Second/Minute/Hour` of the given date.\n\n```js\n// Moment.js\nmoment().seconds(30);\n// =\u003e \"2018-09-09T09:12:30.695Z\"\nmoment().hours(13);\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n\n// Native\nnew Date(new Date().setSeconds(30));\n// =\u003e \"2018-09-09T09:12:30.695Z\"\nnew Date(new Date().setHours(13));\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n\n// date-fns\nimport setSeconds from 'date-fns/setSeconds';\nimport setHours from 'date-fns/setHours';\nsetSeconds(new Date(), 30);\n// =\u003e \"2018-09-09T09:12:30.695Z\"\nsetHours(new Date(), 13);\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n\n// dayjs\ndayjs().set('second', 30);\n// =\u003e \"2018-09-09T09:12:30.695Z\"\ndayjs().set('hour', 13);\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n\n// luxon\nDateTime.utc()\n  .set({ second: 30 })\n  .toJSDate();\n// =\u003e \"2018-09-09T09:12:30.695Z\"\nDateTime.utc()\n  .set({ hour: 13 })\n  .toJSDate();\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().with({ second: 30 });\n// =\u003e \"2018-09-09T09:12:30.695Z\"\nTemporal.Now.zonedDateTimeISO().with({ hour: 13 });\n// =\u003e \"2018-09-09T03:12:49.695Z\"\n```\n\n### Performance tests\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1689.744ms |\n| Native   | 636.741ms  |\n| DateFns  | 714.148ms  |\n| DayJs    | 2037.603ms |\n| Luxon    | 2897.571ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Date of Month\n\nGets or sets the day of the month.\n\n```js\n// Moment.js\nmoment().date();\n// =\u003e 9\nmoment().date(4);\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n\n// Native\nnew Date().getDate();\n// =\u003e 9\nnew Date().setDate(4);\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n\n// date-fns\nimport getDate from 'date-fns/getDate';\nimport setDate from 'date-fns/setDate';\ngetDate(new Date());\n// =\u003e 9\nsetDate(new Date(), 4);\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n\n// dayjs\ndayjs().date();\n// =\u003e 9\ndayjs().set('date', 4);\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n\n// luxon\nDateTime.utc().day;\n// =\u003e 9\nDateTime.utc()\n  .set({ day: 4 })\n  .toString();\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().day;\n// =\u003e 9\nTemporal.Now.zonedDateTimeISO().with({ day: 4 });\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n```\n\n### Performance tests\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1381.669ms |\n| Native   | 397.415ms  |\n| DateFns  | 588.004ms  |\n| DayJs    | 1218.025ms |\n| Luxon    | 2705.606ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Day of Week\n\nGets or sets the day of the week.\n\n```js\n// Moment.js\nmoment().day();\n// =\u003e 0 (Sunday)\nmoment().day(-14);\n// =\u003e \"2018-08-26T09:12:49.695Z\"\n\n// Native\nnew Date().getDay();\n// =\u003e 0 (Sunday)\nnew Date().setDate(new Date().getDate() - 14);\n// =\u003e \"2018-08-26T09:12:49.695Z\"\n\n// date-fns\nimport getDay from 'date-fns/getDay';\nimport setDay from 'date-fns/setDay';\ngetDay(new Date());\n// =\u003e 0 (Sunday)\nsetDay(new Date(), -14);\n// =\u003e \"2018-08-26T09:12:49.695Z\"\n\n// dayjs\ndayjs().day();\n// =\u003e 0 (Sunday)\ndayjs().set('day', -14);\n// =\u003e \"2018-08-26T09:12:49.695Z\"\n\n// Luxon\nDateTime.local().weekday;\n// =\u003e 7 (Sunday)\nDateTime.local()\n  .minus({ day: 14 })\n  .toJSDate();\n// =\u003e \"2018-08-26T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().dayOfWeek;\n// =\u003e 7 (Sunday)\nTemporal.Now.zonedDateTimeISO().subtract(Temporal.Duration.from({ days: 14 }));\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1919.404ms |\n| Native   | 543.466ms  |\n| DateFns  | 841.436ms  |\n| DayJs    | 1229.475ms |\n| Luxon    | 3936.282ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Day of Year\n\nGets or sets the day of the year.\n\n```js\n// Moment.js\nmoment().dayOfYear();\n// =\u003e 252\nmoment().dayOfYear(256);\n// =\u003e \"2018-09-13T09:12:49.695Z\"\n\n// Native\nMath.floor(\n  (new Date() - new Date(new Date().getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24\n);\n// =\u003e 252\n\n// date-fns\nimport getDayOfYear from 'date-fns/getDayOfYear';\nimport setDayOfYear from 'date-fns/setDayOfYear';\ngetDayOfYear(new Date());\n// =\u003e 252\nsetDayOfYear(new Date(), 256);\n// =\u003e \"2018-09-13T09:12:49.695Z\"\n\n// dayjs ⚠️ requires dayOfYear plugin\nimport dayOfYear from 'dayjs/plugin/dayOfYear';\ndayjs.extend(dayOfYear);\ndayjs().dayOfYear();\n// =\u003e 252\ndayjs().dayOfYear(256);\n// =\u003e \"2018-09-13T09:12:49.695Z\"\n\n// Luxon\nDateTime.local().ordinal;\n// =\u003e 252\nDateTime.local()\n  .set({ ordinal: 256 })\n  .toString();\n// =\u003e \"2018-09-13T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().dayOfYear;\n// =\u003e 252\nTemporal.Now.zonedDateTimeISO().with({month: 1, day: 1}).add(Temporal.Duration.from({days: 256}));\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 5511.172ms |\n| Native   | 530.592ms  |\n| DateFns  | 2079.043ms |\n| DayJs    | -          |\n| Luxon    | 3540.810ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Week of Year\n\nGets or sets the week of the year.\n\n```js\n// Moment.js\nmoment().week();\n// =\u003e 37\nmoment().week(24);\n// =\u003e \"2018-06-10T09:12:49.695Z\"\n\n// date-fns\nimport getWeek from 'date-fns/getWeek';\nimport setWeek from 'date-fns/setWeek';\ngetWeek(new Date());\n// =\u003e 37\nsetWeek(new Date(), 24);\n// =\u003e \"2018-06-10T09:12:49.695Z\"\n\n// native getWeek\nconst day = new Date();\nconst MILLISECONDS_IN_WEEK = 604800000;\nconst firstDayOfWeek = 1; // monday as the first day (0 = sunday)\nconst startOfYear = new Date(day.getFullYear(), 0, 1);\nstartOfYear.setDate(\n  startOfYear.getDate() + (firstDayOfWeek - (startOfYear.getDay() % 7))\n);\nconst dayWeek = Math.round((day - startOfYear) / MILLISECONDS_IN_WEEK) + 1;\n// =\u003e 37\n\n// native setWeek\nconst day = new Date();\nconst week = 24;\nconst MILLISECONDS_IN_WEEK = 604800000;\nconst firstDayOfWeek = 1; // monday as the first day (0 = sunday)\nconst startOfYear = new Date(day.getFullYear(), 0, 1);\nstartOfYear.setDate(\n  startOfYear.getDate() + (firstDayOfWeek - (startOfYear.getDay() % 7))\n);\nconst dayWeek = Math.round((day - startOfYear) / MILLISECONDS_IN_WEEK) + 1;\nday.setDate(day.getDate() - (dayWeek - week) * 7);\nday.toISOString();\n// =\u003e \"2018-06-10T09:12:49.794Z\n\n// dayjs ⚠️ requires weekOfYear plugin\nimport weekOfYear from 'dayjs/plugin/weekOfYear';\ndayjs.extend(weekOfYear);\ndayjs().week();\n// =\u003e 37\ndayjs().week(24);\n// =\u003e \"2018-06-10T09:12:49.695Z\"\n\n// Luxon\nDateTime.local().weekNumber;\n// =\u003e 37\nDateTime.local()\n  .set({ weekNumber: 23 })\n  .toString();\n// =\u003e \"2018-06-10T09:12:49.794Z\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().weekOfYear;\n// =\u003e 252\nTemporal.Now.zonedDateTimeISO().with({month: 1, day: 1}).add(Temporal.Duration.from({weeks: 23}));\n// =\u003e \"2018-09-04T09:12:49.695Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 7147.201ms |\n| Native   | 1371.631ms |\n| DateFns  | 5834.815ms |\n| DayJs    | -          |\n| Luxon    | 4514.771ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Days in Month\n\nGet the number of days in the current month.\n\n```js\n// Moment.js\nmoment('2012-02', 'YYYY-MM').daysInMonth();\n// =\u003e 29\n\n// Native\nnew Date(2012, 02, 0).getDate();\n// =\u003e 29\n\n// date-fns\nimport getDaysInMonth from 'date-fns/getDaysInMonth';\ngetDaysInMonth(new Date(2012, 1));\n// =\u003e 29\n\n// dayjs\ndayjs('2012-02').daysInMonth();\n// =\u003e 29\n\n// Luxon\nDateTime.local(2012, 2).daysInMonth;\n// =\u003e 29\n\n// Temporal\n(new Temporal.PlainYearMonth(2012, 2)).daysInMonth\n// or\nTemporal.PlainYearMonth.from('2012-02').daysInMonth\n// =\u003e 29\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 4415.065ms |\n| Native   | 186.196ms  |\n| DateFns  | 634.084ms  |\n| DayJs    | 1922.774ms |\n| Luxon    | 1403.032ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Weeks in Year\n\nGets the number of weeks in the current year, according to ISO weeks.\n\n```js\n// Moment.js\nmoment().isoWeeksInYear();\n// =\u003e 52\n\n// Native\nconst year = new Date().getFullYear();\nconst MILLISECONDS_IN_WEEK = 604800000;\nconst firstMondayThisYear = new Date(+year,   0, 5-(new Date(+year,   0, 4).getDay()||7));\nconst firstMondayNextYear = new Date(+year+1, 0, 5-(new Date(+year+1, 0, 4).getDay()||7));\n(firstMondayNextYear - firstMondayThisYear) / MILLISECONDS_IN_WEEK;\n// =\u003e 52\n\n// date-fns\nimport getISOWeeksInYear from 'date-fns/getISOWeeksInYear';\ngetISOWeeksInYear(new Date());\n// =\u003e 52\n\n// dayjs ⚠️ requires isoWeeksInYear plugin\nimport isoWeeksInYear from 'dayjs/plugin/isoWeeksInYear';\ndayjs.extend(isoWeeksInYear);\ndayjs().isoWeeksInYear();\n// =\u003e 52\n\n// Luxon\nDateTime.local().weeksInWeekYear;\n// =\u003e 52\n\n// Temporal\nTemporal.PlainDate.from({day:31, month:12, year: Temporal.Now.plainDateISO()}).weekOfYear\n// =\u003e 52\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1065.247ms |\n| Native   | -          |\n| DateFns  | 4954.042ms |\n| DayJs    | -          |\n| Luxon    | 1134.483ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Maximum of the given dates\n\nReturns the maximum (most distant future) of the given date.\n\n```js\nconst array = [\n  new Date(2017, 4, 13),\n  new Date(2018, 2, 12),\n  new Date(2016, 0, 10),\n  new Date(2016, 0, 9),\n];\n// Moment.js\nmoment.max(array.map(a =\u003e moment(a)));\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n\n// Native\nnew Date(Math.max.apply(null, array)).toISOString();\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n\n// date-fns\nimport max from 'date-fns/max';\nmax(array);\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n\n// dayjs ⚠️ requires minMax plugin\nimport minMax from 'dayjs/plugin/minMax';\ndayjs.extend(minMax);\ndayjs.max(array.map(a =\u003e dayjs(a)));\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n\n// Luxon\nDateTime.max(...array.map(a =\u003e DateTime.fromJSDate(a))).toJSDate();\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n\n// Temporal\nTemporal.Instant.fromEpochMilliseconds(Math.max.apply(null, array))\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1780.075ms |\n| Native   | 828.332ms  |\n| DateFns  | 980.938ms  |\n| DayJs    | -          |\n| Luxon    | 2694.702ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Minimum of the given dates\n\nReturns the minimum (most distant future) of the given date.\n\n```js\nconst array = [\n  new Date(2017, 4, 13),\n  new Date(2018, 2, 12),\n  new Date(2016, 0, 10),\n  new Date(2016, 0, 9),\n];\n// Moment.js\nmoment.min(array.map(a =\u003e moment(a)));\n// =\u003e \"2016-01-08T13:00:00.000Z\"\n\n// Native\nnew Date(Math.min.apply(null, array)).toISOString();\n// =\u003e \"2016-01-08T13:00:00.000Z\"\n\n// date-fns\nimport min from 'date-fns/min';\nmin(array);\n// =\u003e \"2016-01-08T13:00:00.000Z\"\n\n// dayjs ⚠️ requires minMax plugin\nimport minMax from 'dayjs/plugin/minMax';\ndayjs.extend(minMax);\ndayjs.min(array.map(a =\u003e dayjs(a)));\n// =\u003e \"2016-01-08T13:00:00.000Z\"\n\n// Luxon\nDateTime.min(...array.map(a =\u003e DateTime.fromJSDate(a))).toJSDate();\n// =\u003e \"2016-01-08T13:00:00.000Z\"\n\n// Temporal\nTemporal.Instant.fromEpochMilliseconds(Math.min.apply(null, array))\n// =\u003e \"2018-03-11T13:00:00.000Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1744.459ms |\n| Native   | 819.646ms  |\n| DateFns  | 841.249ms  |\n| DayJs    | -          |\n| Luxon    | 2720.462ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n## Manipulate\n\n### Add\n\nAdd the specified number of days to the given date.\n\n```js\n// Moment.js\nmoment().add(7, 'days');\n// =\u003e \"2018-09-16T09:12:49.695Z\"\n\n// Native\nconst now = new Date();\nnow.setDate(now.getDate() + 7);\n// =\u003e \"Sun Sep 16 2018 09:12:49\"\n\n// date-fns\nimport addDays from 'date-fns/addDays';\naddDays(new Date(), 7);\n// =\u003e \"2018-09-16T09:12:49.695Z\"\n\n// dayjs\ndayjs().add(7, 'day');\n// =\u003e \"2018-09-16T09:12:49.695Z\"\n\n// Luxon\nDateTime.local()\n  .plus({ day: 7 })\n  .toJSDate();\n// =\u003e \"2018-09-16T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().add(Temporal.Duration.from({days: 7}));\n// =\u003e \"2018-09-16T09:12:49.695Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1309.485ms |\n| Native   | 259.932ms  |\n| DateFns  | 385.394ms  |\n| DayJs    | 1911.881ms |\n| Luxon    | 3919.797ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Subtract\n\nSubtract the specified number of days from the given date.\n\n```js\n// Moment.js\nmoment().subtract(7, 'days');\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// Native\nconst now = new Date();\nnow.setDate(now.getDate() - 7);\n// =\u003e Sun Sep 09 2018 09:12:49\n\n// date-fns\nimport subDays from 'date-fns/subDays';\nsubDays(new Date(), 7);\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// dayjs\ndayjs().subtract(7, 'day');\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// Luxon\nDateTime.local()\n  .minus({ day: 7 })\n  .toJSDate();\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().subtract(Temporal.Duration.from({days: 7}));\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1278.384ms |\n| Native   | 215.255ms  |\n| DateFns  | 379.057ms  |\n| DayJs    | 1772.593ms |\n| Luxon    | 4028.866ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### Start of Time\n\nReturn the start of a unit of time for the given date.\n\n```js\n// Moment.js\nmoment().startOf('month');\n// =\u003e \"2018-08-31T14:00:00.000Z\"\n\n// date-fns\nimport startOfMonth from 'date-fns/startOfMonth';\nstartOfMonth(new Date());\n// =\u003e \"2018-08-31T14:00:00.000Z\"\n\n// dayjs\ndayjs().startOf('month');\n// =\u003e \"2018-08-31T14:00:00.000Z\"\n\n// Luxon\nDateTime.local().startOf('month');\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().with({day: 1});\n// =\u003e \"2018-09-01T14:00:00.000Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1078.948ms |\n| Native   | -          |\n| DateFns  | 398.107ms  |\n| DayJs    | 765.358ms  |\n| Luxon    | 2306.765ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n### End of Time\n\nReturn the end of a unit of time for the given date.\n\n```js\n// Moment.js\nmoment().endOf('day');\n// =\u003e \"2018-09-09T13:59:59.999Z\"\n\n// Native\nconst end = new Date();\nend.setHours(23, 59, 59, 999);\nend.toISOString();\n// =\u003e \"2018-09-09T16:59:59.999Z\"\n\n// date-fns\nimport endOfDay from 'date-fns/endOfDay';\nendOfDay(new Date());\n// =\u003e \"2018-09-09T13:59:59.999Z\"\n\n// dayjs\ndayjs().endOf('day');\n// =\u003e \"2018-09-09T13:59:59.999Z\"\n\n// Luxon\nDateTime.local().endOf('day');\n// =\u003e \"2018-09-02T09:12:49.695Z\"\n\n// Temporal\nTemporal.Now.zonedDateTimeISO().withPlainTime(new Temporal.PlainTime(23,59,59,999,999,999));\n// =\u003e \"2018-09-09T16:59:59.999999999Z\"\n```\n\n| Library  | Time       |\n| -------- | ---------- |\n| Moment   | 1241.304ms |\n| Native   | 225.519ms  |\n| DateFns  | 319.773ms  |\n| DayJs    | 914.425ms  |\n| Luxon    | 9920.529ms |\n| Temporal | -          |\n\n**[⬆ back to top](#quick-links)**\n\n## Display\n\n### Format\n\nReturn the formatted date string in the given format.\n\n```js\n// Moment.js\nmoment().format('dddd, MMMM Do YYYY, h:mm:ss A');\n// =\u003e \"Sunday, September 9th 2018, 7:12:49 PM\"\nmoment().format('ddd, hA');\n// =\u003e \"Sun, 7PM\"\n\n// Native\nnew Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'medium' }).format(new Date())\n// =\u003e \"Sunday, September 9, 2018 at 7:12:49 PM\"\nnew Intl.DateTimeFormat('en-US', { weekday: 'short', hour: 'numeric' }).format(new Date())\n// =\u003e \"Sun, 7 PM\"\n\n// date-fns\nimport { intlFormat } from 'date-fns'\nintlFormat(new Date(), { dateStyle: 'full', timeStyle: 'medium' }, { locale: 'en-US', })\n// =\u003e \"Sunday, September 9, 2018 at 7:12:49 PM\"\nintlFormat(new Date(), { weekday: 'short', hour: 'numeric' }, { locale: 'en-US', })\n// =\u003e \"Sun, 7 PM\"\n\n// dayjs\ndayjs().format('dddd, MMMM D YYYY, h:mm:ss A');\n// =\u003e \"Sunday, September 9 2018, 7:12:49 PM\"\ndayjs().format('ddd, hA');\n// =\u003e \"Sun, 7PM\"\n// dayjs ⚠️ requires advancedFormat plugin to support more format tokens\nimport advancedFormat from 'dayjs/plugin/advancedFormat';\ndayjs.extend(advancedFormat);\ndayjs().format('dddd, MMMM Do YYYY, h:mm:ss A');\n// =\u003e \"Sunday, September 9th 2018, 7:12:49 PM\"\n\n// Luxon\nDateTime.fromMillis(time).toFormat('EEEE, MMMM dd yyyy, h:mm:ss a');\n// =\u003e \"Sunday, September 9 2018, 7:12:49 PM\" ⚠️  not support 9th\nDateTime.fromMillis(time).toFormat('EEE, ha');\n// =\u003e \"Sun, 7PM\"\n\n// Temporal\nnew Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'medium' }).format(Temporal.Now.zonedDateTimeISO())\n// =\u003e \"Sunday, September 9, 2018 at 7:12:49 PM\"\nnew Intl.DateTimeFormat('en-US', { weekday: 'short', hour: 'numeric' }).format(Temporal.Now.zonedDateTimeISO())\n// =\u003e \"Sun, 7 PM\"\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Time from now\n\nReturn time from now.\n\n```js\n// Moment.js\nmoment(1536484369695).fromNow();\n// =\u003e \"4 days ago\"\n\n// Native\nnew Intl.RelativeTimeFormat().format(-4, 'day');\n// =\u003e \"4 days ago\"\n\n// date-fns\nimport formatDistance from 'date-fns/formatDistance';\nformatDistance(new Date(1536484369695), new Date(), { addSuffix: true });\n// =\u003e \"4 days ago\"\n\n// dayjs ⚠️ requires relativeTime plugin\nimport relativeTime from 'dayjs/plugin/relativeTime';\ndayjs.extend(relativeTime);\n\ndayjs(1536484369695).fromNow();\n// =\u003e \"5 days ago\" ⚠️  the rounding method of this plugin is different from moment.js and date-fns, use with care.\n\n// luxon requires Intl.RelativeTimeFormat\nDateTime.local(2022, 1, 27).toRelative({ base: this })\n// =\u003e \"in 4 months\"\n\n// Temporal\nnew Intl.RelativeTimeFormat().format(-4, 'day');\n// =\u003e \"4 days ago\"\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Time from x\n\nReturn time from x.\n\n```js\n// Moment.js\nmoment([2007, 0, 27]).to(moment([2007, 0, 29]));\n// =\u003e \"in 2 days\"\n\n// date-fns\nimport formatDistance from 'date-fns/formatDistance';\nformatDistance(new Date(2007, 0, 27), new Date(2007, 0, 29));\n// =\u003e \"2 days\"\n\n// dayjs ⚠️ requires relativeTime plugin\nimport relativeTime from 'dayjs/plugin/relativeTime';\ndayjs.extend(relativeTime);\ndayjs('2007-01-27').to(dayjs('2007-01-29'));\n// =\u003e \"in 2 days\"\n\n// luxon ❌ does not support relative time\n\n// Temporal\nTemporal.PlainDate.from('2007-01-27').until('2007-01-29');\n// =\u003e Temporal.Duration('P2D')\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Difference\n\nGet the unit of time between the given dates.\n\n```js\n// Moment.js\nmoment([2007, 0, 27]).diff(moment([2007, 0, 29]));\n// =\u003e -172800000\nmoment([2007, 0, 27]).diff(moment([2007, 0, 29]), 'days');\n// =\u003e -2\n\n// Native\nnew Date(2007, 0, 27) - new Date(2007, 0, 29);\n// =\u003e -172800000\nMath.ceil(\n  (new Date(2007, 0, 27) - new Date(2007, 0, 29)) / 1000 / 60 / 60 / 24\n);\n// =\u003e -2\n\n// date-fns\nimport differenceInMilliseconds from 'date-fns/differenceInMilliseconds';\ndifferenceInMilliseconds(new Date(2007, 0, 27), new Date(2007, 0, 29));\n// =\u003e -172800000\nimport differenceInDays from 'date-fns/differenceInDays';\ndifferenceInDays(new Date(2007, 0, 27), new Date(2007, 0, 29));\n// =\u003e -2\n\n// dayjs\ndayjs('2007-01-27').diff(dayjs('2007-01-29'), 'milliseconds');\n// =\u003e -172800000\ndayjs('2007-01-27').diff(dayjs('2007-01-29'), 'days');\n// =\u003e -2\n\n// luxon\nDateTime.local(2007, 1, 27).diff(DateTime.local(2007, 1, 29)).milliseconds;\n// =\u003e -172800000\nDateTime.local(2007, 1, 27).diff(DateTime.local(2007, 1, 29), 'days').days;\n// =\u003e -2\n\n// Temporal\nTemporal.PlainDate.from('2007-01-27').since('2007-01-29').total({unit: 'millisecond'});\n// =\u003e -172800000\nTemporal.PlainDate.from('2007-01-27').since('2007-01-29').total({unit: 'day'});\n// =\u003e -2\n```\n\n**[⬆ back to top](#quick-links)**\n\n## Query\n\n### Is Before\n\nCheck if a date is before another date.\n\n```js\n// Moment.js\nmoment('2010-10-20').isBefore('2010-10-21');\n// =\u003e true\n\n// Native\nnew Date(2010, 10, 20) \u003c new Date(2010, 10, 21);\n// =\u003e true\n\n// date-fns\nimport isBefore from 'date-fns/isBefore';\nisBefore(new Date(2010, 9, 20), new Date(2010, 9, 21));\n// =\u003e true\n\n// dayjs\ndayjs('2010-10-20').isBefore('2010-10-21');\n// =\u003e true\n\n// luxon\nDateTime.fromISO('2010-10-20') \u003c DateTime.fromISO('2010-10-21');\n// =\u003e true\n\n// Temporal\nTemporal.PlainDate.compare('2010-10-20', '2010-10-21') === -1;\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Is Same\n\nCheck if a date is the same as another date.\n\n```js\n// Moment.js\nmoment('2010-10-20').isSame('2010-10-21');\n// =\u003e false\nmoment('2010-10-20').isSame('2010-10-20');\n// =\u003e true\nmoment('2010-10-20').isSame('2010-10-21', 'month');\n// =\u003e true\n\n// Native\nnew Date(2010, 9, 20).valueOf() === new Date(2010, 9, 21).valueOf();\n// =\u003e false\nnew Date(2010, 9, 20).valueOf() === new Date(2010, 9, 20).valueOf();\n// =\u003e true\nnew Date(2010, 9, 20).getTime() === new Date(2010, 9, 20).getTime();\n// =\u003e true\nnew Date(2010, 9, 20).valueOf() === new Date(2010, 9, 20).getTime();\n// =\u003e true\nnew Date(2010, 9, 20).toDateString().substring(4, 7) ===\n  new Date(2010, 9, 21).toDateString().substring(4, 7);\n// =\u003e true\n\n// date-fns\nimport isSameDay from 'date-fns/isSameDay';\nimport isSameMonth from 'date-fns/isSameMonth';\nisSameDay(new Date(2010, 9, 20), new Date(2010, 9, 21));\n// =\u003e false\nisSameDay(new Date(2010, 9, 20), new Date(2010, 9, 20));\n// =\u003e true\nisSameMonth(new Date(2010, 9, 20), new Date(2010, 9, 21));\n// =\u003e true\n\n// dayjs\ndayjs('2010-10-20').isSame('2010-10-21');\n// =\u003e false\ndayjs('2010-10-20').isSame('2010-10-20');\n// =\u003e true\ndayjs('2010-10-20').isSame('2010-10-21', 'month');\n// =\u003e true\n\n// luxon\n(+DateTime.fromISO('2010-10-20') ===\n  +DateTime.fromISO('2010-10-21') +\n    // =\u003e false\n    DateTime.fromISO('2010-10-20')) ===\n  +DateTime.fromISO('2010-10-20');\n// =\u003e true\nDateTime.fromISO('2010-10-20').hasSame(DateTime.fromISO('2010-10-21'), 'month');\n// =\u003e true\n\n// Temporal\nTemporal.PlainDate.from('2010-10-20').equals('2010-10-21');\n// =\u003e false\nTemporal.PlainDate.from('2010-10-20').equals('2010-10-20');\n// =\u003e true\nTemporal.PlainDate.from('2010-10-20').month === Temporal.PlainDate.from('2010-10-21').month;\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Is After\n\nCheck if a date is after another date.\n\n```js\n// Moment.js\nmoment('2010-10-20').isAfter('2010-10-19');\n// =\u003e true\n\n// Native\nnew Date(2010, 9, 20) \u003e new Date(2010, 9, 19);\n// =\u003e true\n\n// date-fns\nimport isAfter from 'date-fns/isAfter';\nisAfter(new Date(2010, 9, 20), new Date(2010, 9, 19));\n// =\u003e true\n\n// dayjs\ndayjs('2010-10-20').isAfter('2010-10-19');\n// =\u003e true\n\n// luxon\nDateTime.fromISO('2010-10-20') \u003e DateTime.fromISO('2010-10-19');\n// =\u003e true\n\n// Temporal\nTemporal.PlainDate.compare('2010-10-20', '2010-10-19') === 1;\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Is Between\n\nCheck if a date is between two other dates.\n\n```js\n// Moment.js\nmoment('2010-10-20').isBetween('2010-10-19', '2010-10-25');\n// =\u003e true\n\n// date-fns\nimport isWithinInterval from 'date-fns/isWithinInterval';\nisWithinInterval(new Date(2010, 9, 20), {\n  start: new Date(2010, 9, 19),\n  end: new Date(2010, 9, 25),\n});\n// =\u003e true\n\n// dayjs ⚠️ requires isBetween plugin\nimport isBetween from 'dayjs/plugin/isBetween';\ndayjs.extend(isBetween);\ndayjs('2010-10-20').isBetween('2010-10-19', '2010-10-25');\n// =\u003e true\n\n// luxon\nInterval.fromDateTimes(\n  DateTime.fromISO('2010-10-19'),\n  DateTime.fromISO('2010-10-25')\n).contains(DateTime.fromISO('2010-10-20'));\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Is Leap Year\n\nCheck if a year is a leap year.\n\n```js\n// Moment.js\nmoment([2000]).isLeapYear();\n// =\u003e true\n\n// Native\nnew Date(2000, 1, 29).getDate() === 29;\n// =\u003e true\n\n// date-fns\nimport isLeapYear from 'date-fns/isLeapYear';\nisLeapYear(new Date(2000, 0, 1));\n// =\u003e true\n\n// dayjs ⚠️ requires isLeapYear plugin\nimport isLeapYear from 'dayjs/plugin/isLeapYear';\ndayjs.extend(isLeapYear);\ndayjs('2000-01-01').isLeapYear();\n// =\u003e true\n\n// luxon\nexpect(DateTime.local(2000).isInLeapYear).toBeTruthy();\n// =\u003e true\n\n// Temporal\nTemporal.PlainDate.from('2000-01-01').inLeapYear;\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n### Is a Date\n\nCheck if a variable is a native js Date object.\n\n```js\n// Moment.js\nmoment.isDate(new Date());\n// =\u003e true\n\n// Native\nnew Date() instanceof Date;\n// =\u003e true\n\n// date-fns\nimport isDate from 'date-fns/isDate';\nisDate(new Date());\n// =\u003e true\n\n// dayjs\ndayjs(new Date()).isValid();\n\n// luxon\nDateTime.local().isValid;\n// =\u003e true\n\n// Temporal\nnew Date() instanceof Date;\nTemporal.Now.plainTimeISO() instanceof Temporal.PlainTime;\nTemporal.Now.plainDateISO() instanceof Temporal.PlainDate;\nTemporal.Now.plainDateTimeISO() instanceof Temporal.PlainDateTime;\nTemporal.Now.zonedDateTimeISO() instanceof Temporal.ZonedDateTime;\n// =\u003e true\n```\n\n**[⬆ back to top](#quick-links)**\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyou-dont-need%2FYou-Dont-Need-Momentjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyou-dont-need%2FYou-Dont-Need-Momentjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyou-dont-need%2FYou-Dont-Need-Momentjs/lists"}