Skip to content

Instantly share code, notes, and snippets.

@janxious
Last active March 8, 2016 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janxious/89fe1f3fb84501e524e5 to your computer and use it in GitHub Desktop.
Save janxious/89fe1f3fb84501e524e5 to your computer and use it in GitHub Desktop.
Unix Timestamps Across the Languages

Because every language does this a little differently, here's a collection of ways to compute the unix timestamp. The technical details of what that means can be read on Wikipedia.

# Elixir/Erlang R18+
:os.system_time(:seconds)
# Older
{megasec, sec, _microsec} = :os.timestamp
megasec * 1000000 + sec
package main
import "time"
func main() {
time.Now().Unix()
}
/* JavaScript */
Math.round(Date.now() / 1000)
<?php
# PHP
time()
# Python
import calendar
import time
calendar.timegm(time.localtime())
# Ruby
Time.now.to_i
#!/bin/bash
# shell script
date "+%s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment