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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.