Hello, I have a background in PHP. I have been working with rails for a little wihle now and somethign i still am not understanding is how ruby handles time stamps. What method can i use to get the current time stamp? Also how can i convert that timestamp in to an "english" time? I need to work out times based on weeks. So for example i would have done something like this in php $time_now = time(); $time_one_week_form_now = 60 * 60 * 24 * 7 + time(); how would i do this in ruby? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stewart wrote:> Hello, > > I have a background in PHP. I have been working with rails for a little > wihle now and somethign i still am not understanding is how ruby handles > time stamps. What method can i use to get the current time stamp? Also > how can i convert that timestamp in to an "english" time? > > I need to work out times based on weeks. So for example i would have > done something like this in php > > > $time_now = time(); > $time_one_week_form_now = 60 * 60 * 24 * 7 + time(); > > how would i do this in ruby?ANSWER: http://wiki.rubyonrails.com/rails/pages/PhpDateAndTimeFunctions -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/20/06, Stewart <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello, > > I have a background in PHP. I have been working with rails for a little > wihle now and somethign i still am not understanding is how ruby handles > time stamps. What method can i use to get the current time stamp? Also > how can i convert that timestamp in to an "english" time? > > I need to work out times based on weeks. So for example i would have > done something like this in php > > > $time_now = time(); > $time_one_week_form_now = 60 * 60 * 24 * 7 + time(); > > how would i do this in ruby?Not much different... time_now = Time.now time_one_week_from_now = time_now + 60 * 60 * 24 * 7 http://www.rubycentral.com/book/ref_c_time.html http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/DateTime.html There''s some other date helpers in rails that may be useful too http://rubyonrails.com/rails/classes/ActionView/Helpers/DateHelper.html -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stewart wrote:> Hello, > > I have a background in PHP. I have been working with rails for a little > wihle now and somethign i still am not understanding is how ruby handles > time stamps. What method can i use to get the current time stamp? Also > how can i convert that timestamp in to an "english" time? > > I need to work out times based on weeks. So for example i would have > done something like this in php > > > $time_now = time(); > $time_one_week_form_now = 60 * 60 * 24 * 7 + time(); > > how would i do this in ruby?easy as pie now = Time.now then = 1.week.from_now puts then.strftime(''%Y-%m-%d'') #=> 2006-11-27 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Stewart wrote: > > Hello, > > > > I have a background in PHP. I have been working with rails for a little > > wihle now and somethign i still am not understanding is how ruby handles > > time stamps. What method can i use to get the current time stamp? Also > > how can i convert that timestamp in to an "english" time? > > > > I need to work out times based on weeks. So for example i would have > > done something like this in php > > > > > > $time_now = time(); > > $time_one_week_form_now = 60 * 60 * 24 * 7 + time(); > > > > how would i do this in ruby? > > easy as pie > > now = Time.now > then = 1.week.from_now > > puts then.strftime(''%Y-%m-%d'') > #=> 2006-11-27 > > -- > Posted via http://www.ruby-forum.com/.require ''rubygems'' require ''ruby-units'' require ''chronic'' now = ''now''.time next_week = now + ''1 week''.unit --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Nov 21, 2006 at 06:21:13AM +0100, Alex Wayne wrote:> puts then.strftime(''%Y-%m-%d'') > #=> 2006-11-27In addition you can set the default way Rails prints timestamps and dates as discussed in the thread: http://www.ruby-forum.com/topic/57923 -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---