{"id":19013362,"url":"https://github.com/z41z/fordatetime","last_synced_at":"2026-04-25T22:30:19.073Z","repository":{"id":183235281,"uuid":"669811837","full_name":"z41z/fordatetime","owner":"z41z","description":"DateTime utils.","archived":false,"fork":false,"pushed_at":"2023-07-29T07:07:35.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-01T22:13:19.675Z","etag":null,"topics":["datetime","datetime-format","datetime-next","datetime-prev","datetime-utils"],"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/z41z.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}},"created_at":"2023-07-23T14:05:07.000Z","updated_at":"2023-07-23T14:08:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc8c89d6-8f33-45fe-bf02-52b5a1638820","html_url":"https://github.com/z41z/fordatetime","commit_stats":null,"previous_names":["z41z/fordatetime"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordatetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordatetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordatetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordatetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z41z","download_url":"https://codeload.github.com/z41z/fordatetime/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240051396,"owners_count":19740341,"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":["datetime","datetime-format","datetime-next","datetime-prev","datetime-utils"],"created_at":"2024-11-08T19:23:38.485Z","updated_at":"2026-04-25T22:30:19.026Z","avatar_url":"https://github.com/z41z.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fordatetime\n\nDateTime utils.\n\n## Install\n\n``` node\n  npm i fordatetime //or yarn add fordatetime\n```\n\n### Usage\n\n``` js\n  import DateTime from 'fordatetime'\n  let datetime = new DateTime()\n```\n\n  - #### format\n  ``` js\n    new Date().format('yyyy-MM-dd hh:mm:ss')\n    // 2023-07-29 11:48:17\n  ```\n  - #### prev\n     - {Number} timestamp  \n    ``` js\n      new Date().prev(1e3 * 60 * 60 * 24)\n      // 2023-07-28 11:48:17\n    ```\n  - #### prevDay\n    - {Object} options\n    - {Number} options.day\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevDay({ day: 5 })\n      // 2023-07-24 11:48:17\n      new Date().prevDay({ day: 5, isShowAll: true })\n      // [\n      //   '2023-07-24 11:48:17',\n      //   '2023-07-25 11:48:17',\n      //   '2023-07-26 11:48:17',\n      //   '2023-07-27 11:48:17',\n      //   '2023-07-28 11:48:17' \n      // ]\n      new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true })\n      // [\n      //   '2023-07-25 11:48:17',\n      //   '2023-07-26 11:48:17',\n      //   '2023-07-27 11:48:17',\n      //   '2023-07-28 11:48:17',\n      //   '2023-07-29 11:48:17'\n      // ]\n    ```\n  - #### prevMonth\n    - {Object} options\n    - {Number} options.month\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevMonth({ month: 5, includeCurrent: false, isShowAll: true })\n      // [\n      // '2023-08-31 14:57:02',\n      // '2023-09-30 14:57:02',\n      // '2023-10-31 14:57:02',\n      // '2023-11-30 14:57:02',\n      // '2023-12-31 14:57:02'\n      // ]\n    ```\n  - #### prevYear\n    - {Object} options\n    - {Number} options.year\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true  })\n      // [\n      // '2018-07-29 14:57:57',\n      // '2019-07-29 14:57:57',\n      // '2020-07-29 14:57:57',\n      // '2021-07-29 14:57:57',\n      // '2022-07-29 14:57:57'\n      // ]\n    ```\n  - #### next\n    - {Number} timestamp  \n    ``` js\n      new Date().next(1e3 * 60 * 60 * 24)\n      // 2023-07-30 14:58:50\n    ```\n  - #### nextDay\n    - {Object} options\n    - {Number} options.day\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextDay({ day: 5 })\n      // 2023-08-03 14:59:09\n      new Date().nextDay({ day: 5, isShowAll: true })\n      // [\n      //  '2023-07-30 14:59:28',\n      //  '2023-07-31 14:59:28',\n      //  '2023-08-01 14:59:28',\n      //  '2023-08-02 14:59:28',\n      //  '2023-08-03 14:59:28'\n      // ]\n      new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true })\n      //[\n      //  '2023-07-29 15:00:46',\n      //  '2023-07-30 15:00:46',\n      //  '2023-07-31 15:00:46',\n      //  '2023-08-01 15:00:46',\n      //  '2023-08-02 15:00:46'\n      //]\n    ```\n  - #### nextMonth\n    - {Object} options\n    - {Number} options.month\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true })\n      //[\n      //  '2023-08-31 15:01:24',\n      //  '2023-09-30 15:01:24',\n      //  '2023-10-31 15:01:24',\n      //  '2023-11-30 15:01:24',\n      //  '2023-12-31 15:01:24'\n      //]\n    ```\n  - #### nextYear\n    - {Object} options\n    - {Number} options.year\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextYear({ year: 5, includeCurrent: false, isShowAll: true  })\n      //[\n      //  '2023-07-29 15:01:53',\n      //  '2024-07-29 15:01:53',\n      //  '2025-07-29 15:01:53',\n      //  '2026-07-29 15:01:53',\n      //  '2027-07-29 15:01:53'\n      //]\n    ```\n  - #### split\n    - {Object} options\n    - {Date} options.startTime\n    - {Date} options.endTime\n    - {Number} options.gap `milliseconds`\n    ``` js\n      datetime.split({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-01-10 23:59:59'), gap: 1e3 * 60 * 60 * 24 })\n      //[\n      //  '2022-01-01 00:00:00',\n      //  '2022-01-02 00:00:00',\n      //  '2022-01-03 00:00:00',\n      //  '2022-01-04 00:00:00',\n      //  '2022-01-05 00:00:00',\n      //  '2022-01-06 00:00:00',\n      //  '2022-01-07 00:00:00',\n      //  '2022-01-08 00:00:00',\n      //  '2022-01-09 00:00:00',\n      //  '2022-01-10 00:00:00'\n      // ]\n    ```\n  - #### calc\n    - {Object} options\n    - {Date} options.startTime\n    - {Date} options.endTime\n    - {type} options.type `type values 'year' or 'day', default is 'year'`\n    - {Number} options.offset `timezone offset, default is 8 (8 is China Timezone)`\n    ``` js\n      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') })\n      // { year: 0, month: 10, day: 9, hour: 23, minutes: 59, seconds: 59 }\n      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'})\n      // { day: 313, hour: 23, minutes: 59, seconds: 59 }\n    ```\n  - #### getWeek\n    - {Array} weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']\n    ``` js\n      new Date().getWeek()\n      // 星期日\n      new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六'])\n      // 周日\n    ```\n  - #### getRangeYear\n    ``` js\n      new Date().getRangeYear()\n      // { start: '2023-01-01 00:00:00', end: '2023-12-31 23:59:59' }\n    ```\n  - #### getRangeMonth\n    ``` js\n      new Date().getRangeMonth()\n      // { start: '2023-07-01 00:00:00', end: '2023-07-31 23:59:59' }\n    ```\n  - #### getRangeWeek\n    ``` js\n      new Date().getRangeWeek()\n      // { start: '2023-07-24 00:00:00', end: '2023-07-30 23:59:59' }\n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Ffordatetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz41z%2Ffordatetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Ffordatetime/lists"}