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.
Last active
March 8, 2016 05:26
-
-
Save janxious/89fe1f3fb84501e524e5 to your computer and use it in GitHub Desktop.
Unix Timestamps Across the Languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Elixir/Erlang R18+ | |
:os.system_time(:seconds) | |
# Older | |
{megasec, sec, _microsec} = :os.timestamp | |
megasec * 1000000 + sec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "time" | |
func main() { | |
time.Now().Unix() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* JavaScript */ | |
Math.round(Date.now() / 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# PHP | |
time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python | |
import calendar | |
import time | |
calendar.timegm(time.localtime()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby | |
Time.now.to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# shell script | |
date "+%s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment