{"id":13582000,"url":"https://github.com/sj14/epoch","last_synced_at":"2025-03-27T02:30:59.379Z","repository":{"id":34996749,"uuid":"167670031","full_name":"sj14/epoch","owner":"sj14","description":"🕗 Easily convert epoch timestamps to human-readable formats and vice versa.","archived":false,"fork":false,"pushed_at":"2025-03-18T16:21:41.000Z","size":150,"stargazers_count":26,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-22T22:04:03.362Z","etag":null,"topics":["converter","date","epoch","hacktoberfest","human-readable-formats","time","timestamp"],"latest_commit_sha":null,"homepage":"","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/sj14.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,"publiccode":null,"codemeta":null}},"created_at":"2019-01-26T09:08:25.000Z","updated_at":"2025-03-18T16:21:43.000Z","dependencies_parsed_at":"2024-03-02T10:28:30.049Z","dependency_job_id":"87791c63-0878-4e7a-90ed-504485709cc5","html_url":"https://github.com/sj14/epoch","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fepoch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fepoch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fepoch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fepoch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sj14","download_url":"https://codeload.github.com/sj14/epoch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245769259,"owners_count":20669150,"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":["converter","date","epoch","hacktoberfest","human-readable-formats","time","timestamp"],"created_at":"2024-08-01T15:02:22.561Z","updated_at":"2025-03-27T02:30:59.063Z","avatar_url":"https://github.com/sj14.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# epoch\n\n![Action](https://github.com/sj14/epoch/workflows/Go/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sj14/epoch)](https://goreportcard.com/report/github.com/sj14/epoch)\n[![GoDoc](https://godoc.org/github.com/sj14/epoch/epoch?status.png)](https://godoc.org/github.com/sj14/epoch/epoch)\n\n\u003e [!NOTE]\n\u003e I decided to go back to unstable releases. The major version 0 is the newest version, all other major versions are abandoned.\n\n`epoch` converts unix timestamps to human readable formats and vice versa.\n\n**Why?**  \nTo convert timestamps to dates, you have to run different commands for different `date` implementations, such as GNU's, BSD's or Busybox's date implementation. For example, `date -d @1267619929` (GNU) vs `date -r 1267619929` (BSD), and what about handling nanosecond timestamps? Furthermore, have you ever tried converting a time formatted string such as `\"2019-01-25 21:51:38 +0100 CET\"` to a timestamp? Of course, you can do all this somehow, but all ways I've found so far were too cumbersome. This tool tries to solve all this and more with ease:\n\n```bash\n$ epoch \"2019-01-25 21:51:38 +0100 CET\"\nusing seconds as unit\n1548449498\n```\n\n```bash\n$ epoch 1548449498\nguessed unit: seconds\n2019-01-25 21:51:38 +0100 CET\n```\n\nConvert between timezones:\n\n```bash\n$ epoch -tz \"Europe/Berlin\" \"Sat Jul 18 15:46:45 UTC 2020\"\nSat Jul 18 17:46:45 CEST 2020\n```\n\nTimestamp to formatted string of specific timezone:\n\n```bash\n$ epoch -tz \"America/New_York\" 1595088886\nguessed unit: seconds\n2020-07-18 12:14:46 -0400 EDT\n```\n\nBasic calculations:\n\n```bash\n$ epoch -calc \"-30m +1h -5D +3W -6M +2Y\" -tz \"local\" \"2020-07-18 17:46:45.215239 +0200 CEST\"\n2022-02-03 18:16:45.215239 +0100 CET\n```\n\nThe functionallity is implemented as a package and can be used in other programs.\n\n## Installation\n\n### Precompiled Binaries\n\nBinaries are available for all major platforms. See the [releases](https://github.com/sj14/epoch/releases) page. Usually, `epoch` uses the timezone data from the operating system. When the operating system has no timezone data installed, you can use the 'full' binaries which have this information embedded.\n\n### Homebrew\n\nUsing the [Homebrew](https://brew.sh/) package manager for macOS:\n\n```bash\nbrew install sj14/tap/epoch\n```\n\n### Manually\n\nIt's also possible to install the latest version with `go install`:\n\n```bash\ngo install github.com/sj14/epoch/cmd/epoch@latest\n```\n\n## Usage\n\n```text\nUsage of epoch:\n  -calc string\n        apply basic time calculations, e.g. '+30m -5h +3M -10Y'\n  -format string\n        human readable output format, such as 'rfc3339' (see readme for details)\n  -quiet\n        don't output guessed units\n  -tz string\n        the timezone to use, e.g. 'Local' (default), 'UTC', or a name corresponding to the IANA Time Zone database, such as 'America/New_York'\n  -unit string\n        unit for timestamps: s, ms, us, ns (default \"guess\")\n  -version\n        print version\n```\n\n## Examples\n\n### Timestamps to human readable format\n\n#### conversion based on given unit\n\nUse the `-unit` flag or append the unit at a suffix to the input.\n\n```bash\n$ epoch -unit s 1548449513\nFri Jan 25 21:51:53 CET 2019\n```\n\n```bash\n$ epoch 1548449513s\nFri Jan 25 21:51:53 CET 2019\n```\n\n---\n\n```bash\n$ epoch -unit ms 1548449513\nSun Jan 18 23:07:29 CET 1970\n```\n\n```bash\n$ epoch 1548449513ms\nSun Jan 18 23:07:29 CET 1970\n```\n\n---\n\n```bash\n$ epoch -unit us 1548449513\nThu Jan  1 01:25:48 CET 1970\n```\n\n```bash\n$ epoch 1548449513us\nThu Jan  1 01:25:48 CET 1970\n```\n\n---\n\n```bash\n$ epoch -unit ns 1548449513\nThu Jan  1 01:00:01 CET 1970\n```\n\n```bash\n$ epoch 1548449513ns\nThu Jan  1 01:00:01 CET 1970\n```\n\n#### set the output format\n\n```bash\n$ epoch -unit ms -format rfc850 1548449513\nSunday, 18-Jan-70 23:07:29 CET\n```\n\n```bash\n$ epoch -unit ms -format ruby 1548449513\nSun Jan 18 23:07:29 +0100 1970\n```\n\n```bash\n$ epoch -unit ms -format ansic 1548449513\nSun Jan 18 23:07:29 1970\n```\n\n#### guess the unit\n\nGuess the unit. Internally, the guesssing is done by comparing the absolute difference of the current epoch timestamps (in `s`, `ms`, `us`, `ns`) of your machine with the input value. The smallest difference wins.\n\nseconds:\n\n```bash\n$ epoch 1548449513\nguessed unit seconds\n2019-01-25 21:51:53 +0100 CET\n```\n\nmilliseconds:\n\n```bash\n$ epoch 1548449513940\nguessed unit milliseconds\n2019-01-25 21:51:53 +0100 CET\n```\n\nmicroseconds:\n\n```bash\n$ epoch 1548449513940562\nguessed unit microseconds\n2019-01-25 21:51:53.940562 +0100 CET\n```\n\nnanoseconds:\n\n```bash\n$ epoch 1548449513940562000\nguessed unit nanoseconds\n2019-01-25 21:51:53.940562 +0100 CET\n```\n\n#### negative timestamp\n\n```bash\n$ epoch -- -15484495\nguessed unit: seconds\n1969-07-05 19:45:05 +0100 CET\n```\n\n#### using the pipe\n\n```bash\n$ echo -15484495 | epoch\nguessed unit: seconds\n1969-07-05 19:45:05 +0100 CET\n```\n\n### Formatted input to epoch timestamps\n\nseconds (default when no `unit` flag given):\n\n```bash\n$ epoch -unit s \"2019-01-25 21:51:38.272173 +0100 CET\"\n1548449498\n```\n\nmilliseconds:\n\n```bash\n$ epoch -unit ms \"2019-01-25 21:51:38.272173 +0100 CET\"\n1548449498272\n```\n\nmicroseconds:\n\n```bash\n$ epoch -unit us \"2019-01-25 21:51:38.272173 +0100 CET\"\n1548449498272173\n```\n\nnanoseconds:\n\n```bash\n$ epoch -unit ns \"2019-01-25 21:51:38.272173 +0100 CET\"\n1548449498272173000\n```\n\n### Arithmetics\n\n| Unit | Suffix |\n| ------|--------|\n| Nanoseconds | ns |\n| Microseconds | us |\n| Milliseconds | ms |\n| Seconds | s |\n| Minutes | m |\n| Hours | h |\n| Days | D |\n| Weeks | W |\n| Months | M |\n| Years | Y |\n\n```bash\n$ epoch -calc \"-30m +1h -5D +3W -6M +2Y\" -tz \"local\" \"2020-07-18 17:46:45.215239 +0200 CEST\"\n2022-02-03 18:16:45.215239 +0100 CET\n```\n\n```bash\n$ epoch -calc \"-30m +1h -5D +3W -6M +2Y\" \"2020-07-18 17:46:45.215239 +0200 CEST\"            \nusing seconds as unit\n1643908605\n```\n\n## Supported Formats\n\nAll current Go formats as of 2019-01-26 (https://golang.org/pkg/time/#pkg-constants):\n\n```go\nANSIC       = \"Mon Jan _2 15:04:05 2006\"\nUnixDate    = \"Mon Jan _2 15:04:05 MST 2006\"\nRubyDate    = \"Mon Jan 02 15:04:05 -0700 2006\"\nRFC822      = \"02 Jan 06 15:04 MST\"\nRFC822Z     = \"02 Jan 06 15:04 -0700\" // RFC822 with numeric zone\nRFC850      = \"Monday, 02-Jan-06 15:04:05 MST\"\nRFC1123     = \"Mon, 02 Jan 2006 15:04:05 MST\"\nRFC1123Z    = \"Mon, 02 Jan 2006 15:04:05 -0700\" // RFC1123 with numeric zone\nRFC3339     = \"2006-01-02T15:04:05Z07:00\"\nRFC3339Nano = \"2006-01-02T15:04:05.999999999Z07:00\"\nKitchen     = \"3:04PM\"\n// Handy time stamps.\nStamp      = \"Jan _2 15:04:05\"\nStampMilli = \"Jan _2 15:04:05.000\"\nStampMicro = \"Jan _2 15:04:05.000000\"\nStampNano  = \"Jan _2 15:04:05.000000000\"\n// HTTP Timestamp time.RFC1123 but hard-codes GMT as the time zone.\nHTTP = \"Mon, 02 Jan 2006 15:04:05 GMT\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsj14%2Fepoch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsj14%2Fepoch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsj14%2Fepoch/lists"}