mardi 24 février 2015

Ruby's DateTime class strptime method is subtracting a day from my date object?

Here is the section of the controller that matters:



ap "START DATE IN THE CONTROLLER IS "
ap @selectedJob.start_date
@selectedJob.start_date = DateTime.strptime(@selectedJob.start_date.to_s, ('%m-%d-%Y'))
ap "AFTER THE STRPTIME METHOD"
ap @selectedJob.start_date


I wanted to know what the start_date was before and after my little method - I'm formatting the date part of the date object for display in a start_date input box in the view.


Here is the console output of the above:



"START DATE IN THE CONTROLLER IS "
Sat, 15 Feb 2014
"AFTER THE STRPTIME METHOD"
Fri, 14 Feb 2014


Why is Datetime.strptime subtracting a day from my date object?


When I change DateTime to Time class and call strptime - it correctly formats to Feb 15. What is it about DateTime that's not working and should I discontinue using it?


Aucun commentaire:

Enregistrer un commentaire