{"id":19989975,"url":"https://github.com/uiwjs/date-formatter","last_synced_at":"2025-08-26T14:27:32.116Z","repository":{"id":34520180,"uuid":"174328947","full_name":"uiwjs/date-formatter","owner":"uiwjs","description":"Get a formatted date.","archived":false,"fork":false,"pushed_at":"2024-12-15T18:22:54.000Z","size":284,"stargazers_count":6,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-08T23:49:07.668Z","etag":null,"topics":["date","formatter","javascript","js"],"latest_commit_sha":null,"homepage":"https://uiwjs.github.io/date-formatter/","language":"TypeScript","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/uiwjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"ko_fi":"jaywcjlove","buy_me_a_coffee":"jaywcjlove","custom":["https://www.paypal.me/kennyiseeyou","https://jaywcjlove.github.io/#/sponsor"]}},"created_at":"2019-03-07T11:09:42.000Z","updated_at":"2024-06-24T06:19:21.000Z","dependencies_parsed_at":"2024-06-19T02:43:24.413Z","dependency_job_id":"334f76d2-5cf3-4c0f-bbba-c45b501fcaf7","html_url":"https://github.com/uiwjs/date-formatter","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/uiwjs/date-formatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiwjs%2Fdate-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiwjs%2Fdate-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiwjs%2Fdate-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiwjs%2Fdate-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uiwjs","download_url":"https://codeload.github.com/uiwjs/date-formatter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiwjs%2Fdate-formatter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269669110,"owners_count":24456602,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["date","formatter","javascript","js"],"created_at":"2024-11-13T04:50:52.262Z","updated_at":"2025-08-18T03:32:37.052Z","avatar_url":"https://github.com/uiwjs.png","language":"TypeScript","funding_links":["https://ko-fi.com/jaywcjlove","https://buymeacoffee.com/jaywcjlove","https://www.paypal.me/kennyiseeyou","https://jaywcjlove.github.io/#/sponsor"],"categories":["TypeScript"],"sub_categories":[],"readme":"Formatter\n===\n\n[![GitHub Actions Build formatter](https://github.com/uiwjs/date-formatter/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/date-formatter/actions/workflows/ci.yml) [![](https://img.shields.io/npm/v/@uiw/formatter)](https://www.npmjs.com/package/@uiw/formatter) [![](https://img.shields.io/bundlephobia/min/@uiw/formatter)](https://www.npmjs.com/package/@uiw/formatter) ![](http://jaywcjlove.github.io/sb/status/no-dependencies.svg) [![Coverage Status](https://coveralls.io/repos/github/uiwjs/date-formatter/badge.svg?branch=master)](https://coveralls.io/github/uiwjs/date-formatter?branch=master)\n[![npm downloads](https://img.shields.io/npm/dm/@uiw/formatter.svg?style=flat)](https://www.npmjs.com/package/@uiw/formatter)\n\nGet a formatted date.\n\n[![Demo preview in CodePen](https://shields.io/badge/Demo%20Open%20in-CodePen-success?logo=codepen\u0026style=flat)](https://codepen.io/jaywcjlove/pen/zbZKmq)\n[![Demo preview in CodeSandbox](https://shields.io/badge/Demo%20Open%20in-CodeSandbox-success?logo=codesandbox\u0026style=flat)](https://codesandbox.io/s/date-formatter-demo-jib1u)\n\n### Install\n\n```bash\n$ npm install --save @uiw/formatter\n```\n\n### Usage\n\n```js\nimport formatter from '@uiw/formatter';\n\nconsole.log(formatter());\n//=\u003e 2019-03-07\n\nconsole.log(formatter.utc());\n//=\u003e 2019-03-07\n\nconsole.log(formatter('YYYY年MM月DD日', new Date(2019, 3, 7)))\n//=\u003e 2019年04月07日\nconsole.log(formatter('YYYY年MM月DD日 16:30:29', new Date(2019, 3, 7, 16, 30, 29)))\n//=\u003e 2019年04月07日 16:30:29\nconsole.log(formatter('YYYY年MM月DD日 HH:mm-ss', new Date(2019, 3, 7, 16, 30, 29)))\n//=\u003e 2019年04月07日 16:30-29\nconsole.log(formatter('YYYY/MM/DD HH:mm:ss', new Date(2019, 3, 7, 16, 30, 29)))\n//=\u003e 2019年04月07日 16:30-29\nconsole.log(formatter('YYYY/MM/DD HH:mm:ss', new Date(2019, 3, 7, 16, 30, 29)))\n//=\u003e 2019/04/07 16:30:29\n\n\nconsole.log(formatter('YYYY'));\n//=\u003e 2019\nconsole.log(formatter.utc('YYYY'));\n//=\u003e 2019\n```\n\nOr manually download and link **formatter.js** in your HTML, It can also be downloaded via [UNPKG](https://unpkg.com/@uiw/formatter):\n\n```html\n\u003cdiv id=\"date\"\u003e\u003c/div\u003e\n\u003cscript src=\"https://unpkg.com/@uiw/formatter/dist/formatter.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  document.getElementById('date').innerHTML = formatter();\n\u003c/script\u003e\n```\n\nThe above [example preview](https://codepen.io/jaywcjlove/pen/zbZKmq).\n\n### timeZoneConverter\n\nResolve changes in time zone, resulting in inaccurate display server time\n\n```js\nfunction timeZoneConverter(date, timeZone) {\n  const oldDate = new Date(date);\n  const newDate = new Date();\n  const stamp = oldDate.getTime();\n  if (!timeZone) return oldDate;\n  return (isNaN(timeZone) \u0026\u0026 !timeZone)\n    ? oldDate :\n    new Date(stamp + (newDate.getTimezoneOffset() * 60 * 1000) + (timeZone * 60 * 60 * 1000));\n}\ntimeZoneConverter(new Date(1434701732*1000), 8)\n```\n\n## API\n\n```js\nformatter(rule: String, date: Date, utc: Boolean);\nformatter.utc(rule: String, date: Date);\n```\n\n## Supported Patterns\n\n| rule | Description | 中文说明 | E.g |\n|--------- |-------- |--------- |-------- |\n| `YYYY` | full year | 年 | `2019` |\n| `MM` | month | 月 | `02` |\n| `DD` | day | 天 | `05` |\n| `HH` | hours | 时 | `12` |\n| `mm` | minutes | 分钟 | `59` |\n| `ss` | seconds | 秒 | `09` |\n| `ms` | milliseconds | 毫秒 | `532` |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuiwjs%2Fdate-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuiwjs%2Fdate-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuiwjs%2Fdate-formatter/lists"}