Yukihiro Matsumoto
3/3/2005 11:17:00 PM
In message "Re: Time.parse bug?"
on Fri, 4 Mar 2005 02:39:33 +0900, tony summerfelt <snowzone5@hotmail.com> writes:
|a timestamp line logged yesterday:
|
|02/03/05 22:30:49
|
|that's march 2nd, 2005 est
|
|but this:
|
|require 'time'
|t=Time.parse("02/03/05 22:30:49")
|puts t
|
|outputs this:
|
|Thu Feb 03 22:30:49 EST 2005
|
|
|is there any way to parse the line with a specific format (in this
|case switching the day and month around.
You need to specify the time format explicitly to parse. This small
chunk of code would help.
---
require 'date/format'
def Time.strptime(date, fmt)
Time.mktime(*Date._strptime(date, fmt).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday))
end
---
log = "02/03/05 22:30:49"
p Time.strptime(log, "%d/%m/%y %X")
Time.strptime will be available by default in the future.
matz.