Skip to content
Related Articles

Related Articles

Improve Article
Ruby | DateTime now() function
  • Last Updated : 09 Jan, 2020

DateTime#now() : now() is a DateTime class method which returns a DateTime object denoting the given calendar date.

Syntax: DateTime.now()

Parameter: DateTime values

Return: DateTime object denoting the given calendar date.

Example #1 :






# Ruby code for DateTime.now() method
  
# loading library
require 'date'
  
# declaring DateTime value
date_a = DateTime.now()
  
  
#  now method
puts "DateTime now form : #{date_a}\n\n"

Output :

DateTime now form : 2019-08-30T15:14:33+02:00

Example #2 :




# Ruby code for DateTime.now() method
   
# loading library
require 'date'
   
# declaring DateTime value
date_b = DateTime.now()
   
#  now method
puts "DateTime now form : #{date_b}\n\n"

Output :

DateTime now form : 2019-09-02T10:36:47+00:00

Note : The output depends on the time at which the code runs on your system.

My Personal Notes arrow_drop_up
Recommended Articles
Page :