DateTime parse not working as expected
datetime, parsing, ruby
Solution
This works:
str = "2010-12-02_12-10-26"
puts str
puts DateTime.strptime(str, "%Y-%m-%d_%H-%M-%S")
This example on Codepad.
According to the documentation `parse`:
Create a new DateTime object by parsing from a String, without specifying the format.
And `strptime`:
Create a new DateTime object by parsing from a String according to a specified format.
Problem
I have Ruby code that looks vaguely like this. ``` str = 2010-12-02_12-10-26 puts str puts DateTime.parse(str, "%Y-%m-%d_%H-%M-%S") ``` I expected to get the actual time from the parse. Instead, I'm getting output like this... ``` 2010-12-02_12-10-26 2010-12-02T00:00:00+00:00 ``` How do I get the time parsed in as well?