Answers for "rubyget current time"

0

ruby get current datetime

require 'date'

current_datetime = DateTime.now
Posted by: Guest on April-29-2020
0

ruby time.now

#!/usr/bin/ruby -w

time = Time.new

# Components of a Time
puts "Current Time : " + time.inspect
puts time.year    # => Year of the date 
puts time.month   # => Month of the date (1 to 12)
puts time.day     # => Day of the date (1 to 31 )
puts time.wday    # => 0: Day of week: 0 is Sunday
puts time.yday    # => 365: Day of year
puts time.hour    # => 23: 24-hour clock
puts time.min     # => 59
puts time.sec     # => 59
puts time.usec    # => 999999: microseconds
puts time.zone    # => "UTC": timezone name
Posted by: Guest on June-29-2021

Browse Popular Code Answers by Language