Strftime of datetime
12,182
This should not be necessary, but as a workaround you could try this:
Time.at(
Date.today.to_time.to_i + warning.notify_time_close.seconds
).strftime("%d-%m-%Y %H:%M:%S")
Comments
-
Twiddr almost 2 years
I got the below code which I would like to convert to a string in a specific format. But I can't get it working.
Date.today + warning.notify_time_close.seconds
What I want to do is somethin like this but it doesn't work :)
(Date.today + warning.notify_time_close.seconds).strftime "%d-%m-%Y %H:%M:%S"
I know its simple but just don't know how to do it :)
Thanks in advance!
Kenneth
-
Max Williams over 13 yearsWhat does
warning.notify_time_close
return? If it's an int then the above should work. I'm guessing it isn't. -
Mischa over 13 yearsIf you do
Date.today + 3
it adds three days, not three seconds -
Twiddr over 13 yearsIts an int.. and it works in the console.. but im using it in an RSS builder.. It get this error: undefined method `strftime' for #<String:0x103432430>
-
-
Twiddr over 13 yearsDoesn't work either.. :) Still gets an error: undefined method `strftime' for #<String:0x103629d38>
-
Mischa over 13 yearsWell then
warning.notify_time_close.seconds
is aString
somehow... what happens if you trywarning.notify_time_close.seconds.to_i
? -
Twiddr over 13 yearsStill the same.. Even get the error if i replace warning.notify_time_close with 100.. Its all going on in a feed.rss.builder file - could that be an issue?
-
Twiddr over 13 yearsThis one works: Date.today.to_time.strftime("%d-%m-%Y %H:%M:%S").. But doesn't give me the right result..
-
Mischa over 13 yearsI posted a workaround.. not sure why the stuff in the braces get converted to a
String