Ruby Date and Time

Ruby Date and Time

The Ruby Date, DateTime and Time examples.

Date and Time syntax

Date
DateTime
Time

Date and Time example

cTime = Time.now
puts "Current Time : " + cTime.inspect
puts cTime.year    
puts cTime.month  
puts cTime.day    

require 'date'   
    	
puts DateTime.now	
puts Date.parse('2018-09-22')    
puts Date.strptime('22-09-2018', '%d-%m-%Y')                           
puts Time.new(2018,11,13).to_date  

Output

Current Time : 2018-09-22 09:36:56 +0300

2018

9

22

2018-09-22T09:46:40+03:00

2018-09-22

2018-09-22

2018-11-13