Open In App

Ruby | Time ctime() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The ctime() is an inbuilt method in Ruby returns a canonical string representation of time.

Syntax: time.ctime()

Parameters: The function accepts no parameter

Return Value: It returns a canonical string representation of time.

Example 1:




# Ruby code for ctime() method
  
# Include Time
require 'time'
  
# Declaring time 
a = Time.new(1993, 02, 24, 12, 0, 0, "+09:00")
  
# Prints time as string 
puts a.ctime()


Output:

Wed Feb 24 12:00:00 1993

Example 2:




# Ruby code for ctime() method
  
# Include Time
require 'time'
  
# Declaring time 
a = Time.now.ctime()
  
# Prints time as string 
puts a


Output:

Tue Aug 27 08:22:03 2019

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads