Posted By

chrisaiv on 10/21/07


Tagged

ruby


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

marcio
sergeizen
webstic
tof
concertman
collegeimprovements


101 to using Time in Ruby


 / Published in: Ruby
 

There are many functions available for Time, Month, Day, and Year. Below are a few examples I use frequently

  1. #Find out the Current Time
  2. t = Time.now
  3.  
  4. #Find out the Month, Day, or Year individually
  5. puts t.mon.to_s + "/" + t.day.to_s + "/" + t.year.to_s
  6.  
  7. #Find out the UTC
  8. puts t.utc
  9.  
  10. ###########################
  11. #User Formatted Characters
  12. ###########################
  13. #the String For Time function allows you to mix text with data
  14. puts t.strftime("The Document print data is %m/%d/%Y")
  15.  
  16. #Another way to Display the Month Day, Year
  17. puts t.strftime("%b %d, %Y")

Report this snippet  

You need to login to post a comment.