Skip to content

Instantly share code, notes, and snippets.

@moklett
Created November 5, 2012 16:15
Show Gist options
  • Save moklett/4018049 to your computer and use it in GitHub Desktop.
Save moklett/4018049 to your computer and use it in GitHub Desktop.
Date/Time Formats from Unix Timestamp
t = Time.now
# => 2012-11-05 11:12:25 -0500
t.to_i
# => 1352131945
tu = t.utc
# => 2012-11-05 16:12:25 UTC
tu.to_i
# => 1352131945
php > date_default_timezone_set("UTC");
php > $t = new DateTime("@1352131945");
php > echo date_format($t, "Y-m-d H:i:s");
2012-11-05 16:12:25
php > echo date_format($t, "Y-m-d H:i:s e");
2012-11-05 16:12:25 +00:00
php > $t->setTimezone(new DateTimeZone("America/New_York"));
php > echo date_format($t, "Y-m-d H:i:s e");
2012-11-05 11:12:25 America/New_York
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment