We can use the subsec
attribute to return the subsecond of a Time
object in Ruby. Any Time
object we create in Ruby has access to this attribute.
time_object.subsec
The subsecond of the time_object
is returned. The return value can also be a rational number.
# create time objects time_object_one = Time.now time_object_two = Time.new(2002) time_object_three = Time.new(1999, 10, 02) # get subseconds # and print results puts time_object_one.subsec puts time_object_two.subsec puts time_object_three.subsec
Time
objects using the methods Time.now
and Time.new()
.subsec
attribute on the Time
objects we created and print their values to the console.RELATED TAGS
CONTRIBUTOR
View all Courses