Open In App

Ruby | DateTime now() function

Last Updated : 09 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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
# 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
# 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.

Next Article

Similar Reads