{"id":13697800,"url":"https://github.com/techgaun/unix-time","last_synced_at":"2026-05-14T13:33:12.285Z","repository":{"id":35741049,"uuid":"40019962","full_name":"techgaun/unix-time","owner":"techgaun","description":"Unix time in various languages - A reference","archived":false,"fork":false,"pushed_at":"2017-04-02T20:25:50.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-31T12:02:32.479Z","etag":null,"topics":["java","javascript","time","timestamp","unix"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techgaun.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-31T18:48:51.000Z","updated_at":"2024-10-01T10:23:20.000Z","dependencies_parsed_at":"2022-08-18T06:29:19.556Z","dependency_job_id":null,"html_url":"https://github.com/techgaun/unix-time","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/techgaun/unix-time","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Funix-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Funix-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Funix-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Funix-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techgaun","download_url":"https://codeload.github.com/techgaun/unix-time/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Funix-time/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33026856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"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":["java","javascript","time","timestamp","unix"],"created_at":"2024-08-02T18:01:03.039Z","updated_at":"2026-05-14T13:33:12.199Z","avatar_url":"https://github.com/techgaun.png","language":null,"funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# unix-time\nUnix time in various languages - A reference\n\n### What is [Unix time](https://en.wikipedia.org/wiki/Unix_time)?\nUnix time (also known as POSIX time or erroneously as Epoch time) is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds.\n\n### Examples\n\n#### How to get current unix time\n\n_UTaaS (Unix Timestamp as a Service) (generic)_\n\n```shell\ncurl https://icanhazepoch.com/\n```\n\n_C_\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003ctime.h\u003e\n\nint main(int argc, char **argv) {\n  unsigned int unix_time = (unsigned) time(NULL);\n  fprintf(stdout, \"%u\\n\", unix_time);\n  return 0;\n}\n```\n\n_C++_\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cctime\u003e\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n  unsigned int unix_time = (unsigned) time(NULL);\n  cout \u003c\u003c unix_time \u003c\u003c endl;\n  return 0;\n}\n```\n\n_Elixir_\n\n```elixir\n# first way\nDateTime.utc_now |\u003e DateTime.to_unix\n\n# second way\nSystem.system_time(:second)\n```\n\n_Erlang_\n\n```erlang\nos:system_time(second).\n```\n\n_Golang_\n\n```go\nnow := time.Now()\nunixTs := now.Unix()\n```\n\n_Java_\n\n```java\nlong timestamp = System.currentTimeMillis()/1000;\nSystem.out.println(timestamp);\n```\n\nJava 8 brings a new API to work with date and times, [Instant](http://docs.oracle.com/javase/8/docs/api/java/time/Instant.html). A good read about why [JSR-310 is not same as joda-time](http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html). You can get current unix time on Java 8 by doing something like below:\n\n```java\nlong timestamp = Instant.now().getEpochSecond();\nSystem.out.println(timestamp);\n```\n\n_Javascript_\n\n```javascript\nMath.floor(new Date() / 1000)\n```\n\n[Moment](https://github.com/moment/moment/) is very popular in javascript world for playing with dates in javascript. Below is the momentjs example.\n\n```javascript\nvar moment = require('moment');\nvar unixtime = moment().unix();\n```\n\n_PHP_\n\n```php\necho time();\n\n//php5.3 and above\n//OOP style\n$date = new DateTime();\necho $date-\u003egetTimestamp();\n\n//procedural style\n$date = date_create();\necho date_timestamp_get($date);\n```\n\n_Python_\n\n```python\nfrom time import time\nprint(int(time()))\n\nimport datetime\nprint(int(datetime.datetime.utcnow().timestamp()))\n```\n\n_Ruby_\n\n```ruby\nTime.now.to_i\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechgaun%2Funix-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechgaun%2Funix-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechgaun%2Funix-time/lists"}