Skip to content

Instantly share code, notes, and snippets.

@olistik
Created November 7, 2010 15:50
Show Gist options
  • Save olistik/666193 to your computer and use it in GitHub Desktop.
Save olistik/666193 to your computer and use it in GitHub Desktop.
## IS THERE A SIMPLER WAY OF CHANGING some fields of a DateTime Object?
real = DateTime.parse(DateTime.now.to_s)
fixed = DateTime.new(real.year, real.month, real.day, real.hour, real.minute, real.second)
## SOLUTION
## http://api.rubyonrails.org/classes/DateTime.html
## DateTime#change
new_date = DateTime.now.change({year: 2012, sec: 42})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment