Skip to content
class method

Time.now

(?in: ::String | ::Integer | nil) -> ::Time
now(in: nil)

Creates a new Time object from the current system time. This is the same as Time.new without arguments.

Example
Time.now               # => 2009-06-24 12:39:54 +0900
Time.now(in: '+04:00') # => 2009-06-24 07:39:54 +0400

For forms of argument zone, see Timezone Specifiers.

Ruby version changes

  1. 3.1
    • Time.new now accepts optional in: keyword argument for the timezone, as well as Time.at and Time.now, so that is now you can omit minor arguments to Time.new. [Feature #17485]

      Example
      Time.new(2021, 12, 25, in: "+07:00")
      #=> 2021-12-25 00:00:00 +0700
      

      At the same time, time component strings are converted to integers more strictly now.

      Example
      Time.new(2021, 12, 25, "+07:30")
      #=> invalid value for Integer(): "+07:30" (ArgumentError)
      

      Ruby 3.0 or earlier returned probably unexpected result 2021-12-25 07:00:00, not 2021-12-25 07:30:00 nor 2021-12-25 00:00:00 +07:30.

See also .new .parse .mktime .rfc2822 also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0