Skip to content

Instantly share code, notes, and snippets.

@dentarg
Last active July 16, 2025 02:07
Show Gist options
  • Select an option

  • Save dentarg/7220704 to your computer and use it in GitHub Desktop.

Select an option

Save dentarg/7220704 to your computer and use it in GitHub Desktop.
Ruby time and date classes
@dentarg
Copy link
Author

dentarg commented Feb 19, 2014

[104] pry(main)> Time.now.strftime("%F %H:%M")
=> "2014-02-19 22:18"

[105] pry(main)> Time.parse(Time.now.strftime("%F %H:%M"))
=> 2014-02-19 22:18:00 +0100

[106] pry(main)> Time.parse(Time.now.strftime("%F %H:%M") + 'Z')
=> 2014-02-19 22:18:00 UTC

[107] pry(main)> Time.parse(Time.now.strftime("%F %H:%M")).utc
=> 2014-02-19 21:18:00 UTC

[108] pry(main)> Time.parse(Time.now.strftime("%F %H:%M") + 'Z').utc
=> 2014-02-19 22:18:00 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment