{"id":13402781,"url":"https://github.com/sindresorhus/pretty-ms","last_synced_at":"2025-05-12T15:28:15.738Z","repository":{"id":15217383,"uuid":"17945902","full_name":"sindresorhus/pretty-ms","owner":"sindresorhus","description":"Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`","archived":false,"fork":false,"pushed_at":"2024-11-15T09:37:30.000Z","size":81,"stargazers_count":1154,"open_issues_count":1,"forks_count":67,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-10T17:25:29.434Z","etag":null,"topics":["humanize","milliseconds","npm-package"],"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/sindresorhus.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":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-03-20T14:36:57.000Z","updated_at":"2025-05-08T02:12:39.000Z","dependencies_parsed_at":"2025-04-18T16:34:16.385Z","dependency_job_id":"11ef7761-f74c-4708-ba37-a37549fd6bc4","html_url":"https://github.com/sindresorhus/pretty-ms","commit_stats":{"total_commits":87,"total_committers":21,"mean_commits":4.142857142857143,"dds":0.3448275862068966,"last_synced_commit":"d00183f8a040315005452f6f6dec30c581b258a2"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-ms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-ms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-ms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-ms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/pretty-ms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253561432,"owners_count":21927787,"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":["humanize","milliseconds","npm-package"],"created_at":"2024-07-30T19:01:20.783Z","updated_at":"2025-05-12T15:28:15.716Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Packages","Repository","包","others","Humanize","目录","Modules","Number","模块"],"sub_categories":["Humanize","Date \u0026 Time","人性化","日期和时间"],"readme":"# pretty-ms\n\n\u003e Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`\n\n## Install\n\n```sh\nnpm install pretty-ms\n```\n\n## Usage\n\n```js\nimport prettyMilliseconds from 'pretty-ms';\n\nprettyMilliseconds(1337000000);\n//=\u003e '15d 11h 23m 20s'\n\nprettyMilliseconds(1337000000n);\n//=\u003e '15d 11h 23m 20s'\n\nprettyMilliseconds(1337);\n//=\u003e '1.3s'\n\nprettyMilliseconds(133);\n//=\u003e '133ms'\n\n// `compact` option\nprettyMilliseconds(1337, {compact: true});\n//=\u003e '1s'\n\n// `verbose` option\nprettyMilliseconds(1335669000, {verbose: true});\n//=\u003e '15 days 11 hours 1 minute 9 seconds'\n\n// `colonNotation` option\nprettyMilliseconds(95500, {colonNotation: true});\n//=\u003e '1:35.5'\n\n// `formatSubMilliseconds` option\nprettyMilliseconds(100.400080, {formatSubMilliseconds: true})\n//=\u003e '100ms 400µs 80ns'\n\n// Can be useful for time durations\nprettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))\n//=\u003e '35m'\n```\n\n## API\n\n### prettyMilliseconds(milliseconds, options?)\n\n#### milliseconds\n\nType: `number | bigint`\n\nMilliseconds to humanize.\n\n#### options\n\nType: `object`\n\n##### secondsDecimalDigits\n\nType: `number`\\\nDefault: `1`\n\nNumber of digits to appear after the seconds decimal point.\n\n##### millisecondsDecimalDigits\n\nType: `number`\\\nDefault: `0`\n\nNumber of digits to appear after the milliseconds decimal point.\n\nUseful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time).\n\n##### keepDecimalsOnWholeSeconds\n\nType: `boolean`\\\nDefault: `false`\n\nKeep milliseconds on whole seconds: `13s` → `13.0s`.\n\nUseful when you are showing a number of seconds spent on an operation and don't want the width of the output to change when hitting a whole number.\n\n##### compact\n\nType: `boolean`\\\nDefault: `false`\n\nOnly show the first unit: `1h 10m` → `1h`.\n\nAlso ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.\n\n##### unitCount\n\nType: `number`\\\nDefault: `Infinity`\n\nNumber of units to show. Setting `compact` to `true` overrides this option.\n\n##### verbose\n\nType: `boolean`\\\nDefault: `false`\n\nUse full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`\n\n##### separateMilliseconds\n\nType: `boolean`\\\nDefault: `false`\n\nShow milliseconds separately. This means they won't be included in the decimal part of the seconds.\n\n##### formatSubMilliseconds\n\nType: `boolean`\\\nDefault: `false`\n\nShow microseconds and nanoseconds.\n\n##### colonNotation\n\nType: `boolean`\\\nDefault: `false`\n\nDisplay time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`\n\nUseful when you want to display time without the time units, similar to a digital watch.\n\nSetting `colonNotation` to `true` overrides the following options to `false`:\n- `compact`\n- `formatSubMilliseconds`\n- `separateMilliseconds`\n- `verbose`\n\n##### hideYear\n\nType: `boolean`\\\nDefault: `false`\n\nHides the year and shows the hidden year additionally as days (365 per year): `1y 3d 5h 1m 45s` → `368d 5h 1m 45s`.\n\n##### hideYearAndDays\n\nType: `boolean`\\\nDefault: `false`\n\nHides the year and days and shows the hidden values additionally as hours: `1y 3d 5h 1m 45s` → `8837h 1m 45s`.\n\n##### hideSeconds\n\nType: `boolean`\\\nDefault: `false`\n\nHides the seconds: `1y 3d 5h 1m 45s` → `1y 3d 5h 1m`.\n\n## Related\n\n- [pretty-ms-cli](https://github.com/sindresorhus/pretty-ms-cli) - CLI for this module\n- [parse-ms](https://github.com/sindresorhus/parse-ms) - Parse milliseconds into an object\n- [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - Convert an object of time properties to milliseconds\n- [pretty-bytes](https://github.com/sindresorhus/pretty-bytes) - Convert bytes to a human readable string\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpretty-ms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fpretty-ms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpretty-ms/lists"}