{"id":19448207,"url":"https://github.com/csbun/silly-datetime","last_synced_at":"2025-10-30T13:39:16.215Z","repository":{"id":58246091,"uuid":"38602346","full_name":"csbun/silly-datetime","owner":"csbun","description":"simple datetime formater","archived":false,"fork":false,"pushed_at":"2015-12-23T08:45:28.000Z","size":15,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T05:46:32.259Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/csbun.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}},"created_at":"2015-07-06T06:49:25.000Z","updated_at":"2022-12-26T02:45:50.000Z","dependencies_parsed_at":"2022-08-31T00:21:19.258Z","dependency_job_id":null,"html_url":"https://github.com/csbun/silly-datetime","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csbun%2Fsilly-datetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csbun%2Fsilly-datetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csbun%2Fsilly-datetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csbun%2Fsilly-datetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csbun","download_url":"https://codeload.github.com/csbun/silly-datetime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250741891,"owners_count":21479688,"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":[],"created_at":"2024-11-10T16:24:58.023Z","updated_at":"2025-10-30T13:39:16.136Z","avatar_url":"https://github.com/csbun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# silly-datetime\n\nSimple datetime formater\n\n[![NPM](https://nodei.co/npm/silly-datetime.png?compact=true)](https://nodei.co/npm/silly-datetime/)\n\n[![Build Status](https://travis-ci.org/csbun/silly-datetime.svg)](https://travis-ci.org/csbun/silly-datetime)\n[![Coverage Status](https://coveralls.io/repos/csbun/silly-datetime/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/csbun/silly-datetime?branch=master)\n\n## Install\n\n### npm\n\n```sh\nnpm i silly-datetime --save\n```\n\n### bower\n\n```sh\nbower install silly-datetime --save\n```\n\n## Example\n\n```javascript\nvar sd = require('silly-datetime');\nsd.format(new Date(), 'YYYY-MM-DD HH:mm');\n// 2015-07-06 15:10\n\nsd.fromNow(+new Date() - 2000);\n// a few seconds ago\n```\n\nES2015:\n\n```javascript\nimport {\n    format,\n    fromNow\n} from 'silly-datetime';\nformat(new Date(), 'YYYY-MM-DD HH:mm'); // 2015-07-06 15:10\nfromNow(+new Date() - 2000); // a few seconds ago\n```\n\n## Usage\n\n### .format(datetime, format)\n\nFormat a Date object to specified format.\n\n- datetime: Date Object\n- format: formate string, default to `'YYYY-MM-DD HH:mm:ss'`\n\nFormat | Example | Description\n------ | ------- | -----------\n`YYYY` | `2015`  | 4 digit year\n`M MM` | `0..12` | Month number\n`D DD` | `0..31` | Day of month\n`H HH` | `0..23` | 24 hour time\n`h hh` | `1..12` | 12 hour time used with `a A`.\n`a A`  | `am pm` | Post or ante meridiem\n`m mm` | `0..59` | Minutes\n`s ss` | `0..59` | Seconds\n\n```javascript\nsd.format(new Date(), 'YYYY-MM-DD HH:mm');\n// 2015-07-06 15:10\n```\n\n### .fromNow(datetime)\n\nTime from now. This is sometimes called timeago or relative time.\n\n- datetime: Date Object\n\n```javascript\nsd.fromNow(+new Date() - 2000);\n// a few seconds ago\n```\n\n### .locate(newLocale)\n\nChanging locale globally. By default, silly-datetime comes with English locale strings.\n\n- newLocale: locate string or locate Object\n\nLocate string can be `en` (default) or `zh-cn`;\n\n```javascript\nvar datetime = +new Date() + 10 * 60 * 1000;\nsd.locate('zh-cn')\nsd.fromNow(datetime);\n// 10分钟内\n```\n\nOr just pass an custom locate object with any of the key in the table below:\n\nkey      | en              | zh-cn\n-------- | --------------- | ------\n`future` | `in %s`         | `%s内`\n`past`   | `%s ago`        | `%s前`\n`s`      | `a few seconds` | `刚刚`\n`mm`     | `%s minutes`    | `%s分钟`\n`hh`     | `%s hours`      | `%s小时`\n`dd`     | `%s days`       | `%s天`\n`MM`     | `%s months`     | `%s月`\n`yy`     | `%s years`      | `%s年`\n\n```javascript\nsd.locate({\n  past: '%s之前',\n  hh: '%s小時'\n});\nvar datetime = +new Date() + 10 * 60 * 60 * 1000;\nsd.fromNow(datetime);\n// 10小時之前\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsbun%2Fsilly-datetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsbun%2Fsilly-datetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsbun%2Fsilly-datetime/lists"}