{"id":13412488,"url":"https://github.com/jinzhu/now","last_synced_at":"2025-05-12T15:24:04.258Z","repository":{"id":11922808,"uuid":"14489838","full_name":"jinzhu/now","owner":"jinzhu","description":"Now is a time toolkit for golang","archived":false,"fork":false,"pushed_at":"2023-05-22T10:32:40.000Z","size":84,"stargazers_count":4525,"open_issues_count":14,"forks_count":237,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-05-12T15:24:01.686Z","etag":null,"topics":["go","golang","time"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/jinzhu.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":"2013-11-18T10:55:30.000Z","updated_at":"2025-05-11T14:32:29.000Z","dependencies_parsed_at":"2024-01-30T04:54:15.552Z","dependency_job_id":null,"html_url":"https://github.com/jinzhu/now","commit_stats":{"total_commits":70,"total_committers":20,"mean_commits":3.5,"dds":"0.41428571428571426","last_synced_commit":"f067b166b35a996b9ff5a0f610225e1458f23adc"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinzhu%2Fnow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinzhu%2Fnow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinzhu%2Fnow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinzhu%2Fnow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinzhu","download_url":"https://codeload.github.com/jinzhu/now/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253764120,"owners_count":21960517,"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":["go","golang","time"],"created_at":"2024-07-30T20:01:25.241Z","updated_at":"2025-05-12T15:24:04.232Z","avatar_url":"https://github.com/jinzhu.png","language":"Go","funding_links":[],"categories":["开源类库","Date and Time","Go","Date \u0026 Time","Uncategorized","Open source library","日期和时间","日期和時間","Relational Databases","日期和时间`用于处理日期和时间的库`","\u003cspan id=\"日期和时间-date-and-time\"\u003e日期和时间 Date and Time\u003c/span\u003e"],"sub_categories":["日期时间","Search and Analytic Databases","Advanced Console UIs","Uncategorized","Appointment Time","检索及分析资料库","Middlewares","高級控制台界面","高级控制台界面","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"## Now\n\nNow is a time toolkit for golang\n\n[![go report card](https://goreportcard.com/badge/github.com/jinzhu/now \"go report card\")](https://goreportcard.com/report/github.com/jinzhu/now)\n[![test status](https://github.com/jinzhu/now/workflows/tests/badge.svg?branch=master \"test status\")](https://github.com/jinzhu/now/actions)\n[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n\n## Install\n\n```\ngo get -u github.com/jinzhu/now\n```\n\n## Usage\n\nCalculating time based on current time\n\n```go\nimport \"github.com/jinzhu/now\"\n\ntime.Now() // 2013-11-18 17:51:49.123456789 Mon\n\nnow.BeginningOfMinute()        // 2013-11-18 17:51:00 Mon\nnow.BeginningOfHour()          // 2013-11-18 17:00:00 Mon\nnow.BeginningOfDay()           // 2013-11-18 00:00:00 Mon\nnow.BeginningOfWeek()          // 2013-11-17 00:00:00 Sun\nnow.BeginningOfMonth()         // 2013-11-01 00:00:00 Fri\nnow.BeginningOfQuarter()       // 2013-10-01 00:00:00 Tue\nnow.BeginningOfYear()          // 2013-01-01 00:00:00 Tue\n\nnow.EndOfMinute()              // 2013-11-18 17:51:59.999999999 Mon\nnow.EndOfHour()                // 2013-11-18 17:59:59.999999999 Mon\nnow.EndOfDay()                 // 2013-11-18 23:59:59.999999999 Mon\nnow.EndOfWeek()                // 2013-11-23 23:59:59.999999999 Sat\nnow.EndOfMonth()               // 2013-11-30 23:59:59.999999999 Sat\nnow.EndOfQuarter()             // 2013-12-31 23:59:59.999999999 Tue\nnow.EndOfYear()                // 2013-12-31 23:59:59.999999999 Tue\n\nnow.WeekStartDay = time.Monday // Set Monday as first day, default is Sunday\nnow.EndOfWeek()                // 2013-11-24 23:59:59.999999999 Sun\n```\n\nCalculating time based on another time\n\n```go\nt := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.Now().Location())\nnow.With(t).EndOfMonth()   // 2013-02-28 23:59:59.999999999 Thu\n```\n\nCalculating time based on configuration\n\n```go\nlocation, err := time.LoadLocation(\"Asia/Shanghai\")\n\nmyConfig := \u0026now.Config{\n\tWeekStartDay: time.Monday,\n\tTimeLocation: location,\n\tTimeFormats: []string{\"2006-01-02 15:04:05\"},\n}\n\nt := time.Date(2013, 11, 18, 17, 51, 49, 123456789, time.Now().Location()) // // 2013-11-18 17:51:49.123456789 Mon\nmyConfig.With(t).BeginningOfWeek()         // 2013-11-18 00:00:00 Mon\n\nmyConfig.Parse(\"2002-10-12 22:14:01\")     // 2002-10-12 22:14:01\nmyConfig.Parse(\"2002-10-12 22:14\")        // returns error 'can't parse string as time: 2002-10-12 22:14'\n```\n\n### Monday/Sunday\n\nDon't be bothered with the `WeekStartDay` setting, you can use `Monday`, `Sunday`\n\n```go\nnow.Monday()              // 2013-11-18 00:00:00 Mon\nnow.Monday(\"17:44\")       // 2013-11-18 17:44:00 Mon\nnow.Sunday()              // 2013-11-24 00:00:00 Sun (Next Sunday)\nnow.Sunday(\"18:19:24\")    // 2013-11-24 18:19:24 Sun (Next Sunday)\nnow.EndOfSunday()         // 2013-11-24 23:59:59.999999999 Sun (End of next Sunday)\n\nt := time.Date(2013, 11, 24, 17, 51, 49, 123456789, time.Now().Location()) // 2013-11-24 17:51:49.123456789 Sun\nnow.With(t).Monday()              // 2013-11-18 00:00:00 Mon (Last Monday if today is Sunday)\nnow.With(t).Monday(\"17:44\")       // 2013-11-18 17:44:00 Mon (Last Monday if today is Sunday)\nnow.With(t).Sunday()              // 2013-11-24 00:00:00 Sun (Beginning Of Today if today is Sunday)\nnow.With(t).Sunday(\"18:19:24\")    // 2013-11-24 18:19:24 Sun (Beginning Of Today if today is Sunday)\nnow.With(t).EndOfSunday()         // 2013-11-24 23:59:59.999999999 Sun (End of Today if today is Sunday)\n```\n\n### Parse String to Time\n\n```go\ntime.Now() // 2013-11-18 17:51:49.123456789 Mon\n\n// Parse(string) (time.Time, error)\nt, err := now.Parse(\"2017\")                // 2017-01-01 00:00:00, nil\nt, err := now.Parse(\"2017-10\")             // 2017-10-01 00:00:00, nil\nt, err := now.Parse(\"2017-10-13\")          // 2017-10-13 00:00:00, nil\nt, err := now.Parse(\"1999-12-12 12\")       // 1999-12-12 12:00:00, nil\nt, err := now.Parse(\"1999-12-12 12:20\")    // 1999-12-12 12:20:00, nil\nt, err := now.Parse(\"1999-12-12 12:20:21\") // 1999-12-12 12:20:21, nil\nt, err := now.Parse(\"10-13\")               // 2013-10-13 00:00:00, nil\nt, err := now.Parse(\"12:20\")               // 2013-11-18 12:20:00, nil\nt, err := now.Parse(\"12:20:13\")            // 2013-11-18 12:20:13, nil\nt, err := now.Parse(\"14\")                  // 2013-11-18 14:00:00, nil\nt, err := now.Parse(\"99:99\")               // 2013-11-18 12:20:00, Can't parse string as time: 99:99\n\n// MustParse must parse string to time or it will panic\nnow.MustParse(\"2013-01-13\")             // 2013-01-13 00:00:00\nnow.MustParse(\"02-17\")                  // 2013-02-17 00:00:00\nnow.MustParse(\"2-17\")                   // 2013-02-17 00:00:00\nnow.MustParse(\"8\")                      // 2013-11-18 08:00:00\nnow.MustParse(\"2002-10-12 22:14\")       // 2002-10-12 22:14:00\nnow.MustParse(\"99:99\")                  // panic: Can't parse string as time: 99:99\n```\n\nExtend `now` to support more formats is quite easy, just update `now.TimeFormats` with other time layouts, e.g:\n\n```go\nnow.TimeFormats = append(now.TimeFormats, \"02 Jan 2006 15:04\")\n```\n\nPlease send me pull requests if you want a format to be supported officially\n\n## Contributing\n\nYou can help to make the project better, check out [http://gorm.io/contribute.html](http://gorm.io/contribute.html) for things you can do.\n\n# Author\n\n**jinzhu**\n\n* \u003chttp://github.com/jinzhu\u003e\n* \u003cwosmvp@gmail.com\u003e\n* \u003chttp://twitter.com/zhangjinzhu\u003e\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinzhu%2Fnow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinzhu%2Fnow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinzhu%2Fnow/lists"}