Open In App

Ruby | DateTime now() function

Improve
Improve
Like Article
Like
Save
Share
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 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.


Last Updated : 09 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads