現在の日付と時刻を取得する
Date
、Time
、DateTime
で現在の日付と時刻を取得する方法をまとめる。
現在の日付を取得するには以下のようにする。
reuiqre 'date' Date.today
現在の時刻を取得するには以下のようにする。
Time.now
なおDateTime
クラスの場合もnow
メソッドを使う。
require 'date' DateTime.now
Date
、Time
、DateTime
で現在の日付と時刻を取得する方法をまとめる。
現在の日付を取得するには以下のようにする。
reuiqre 'date' Date.today
現在の時刻を取得するには以下のようにする。
Time.now
なおDateTime
クラスの場合もnow
メソッドを使う。
require 'date' DateTime.now