Ruby Basic Exercises: Display the current date and time
Ruby Basic: Exercise-2 with Solution
Write a Ruby program to display the current date and time.
Ruby Code:
require 'date'
current_time = DateTime.now
cdt = current_time.strftime "%d/%m/%Y %H:%M"
puts "Current Date and Time: "+cdt
Output:
Current Date and Time: 27/12/2017 10:30
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Contribute your code and comments through Disqus.
Previous: Write Ruby program to get ruby version with patch number.
Next: Write a Ruby program to create a new string which is n copies of a given string where n is a non-negative integer.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/ruby-exercises/basic/ruby-basic-exercise-2.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics