回答:
フォーマットは次のように行うことができます(HH:SSの代わりにHH:MMを意味すると想定しましたが、変更は簡単です)。
Time.now.strftime("%d/%m/%Y %H:%M")
#=> "14/09/2011 14:09"
シフティング用に更新:
d = DateTime.now
d.strftime("%d/%m/%Y %H:%M")
#=> "11/06/2017 18:11"
d.next_month.strftime("%d/%m/%Y %H:%M")
#=> "11/07/2017 18:11"
このために必要require 'date'
です。
Date
オブジェクトを取得するための最良の方法であるという提案ではありませんでした。とにかく、私はあなたのコメントを、現在のRubyバージョン用にこの回答を最終的に更新する機会と捉えました。
require 'date'
current_time = DateTime.now
current_time.strftime "%d/%m/%Y %H:%M"
# => "14/09/2011 17:02"
current_time.next_month.strftime "%d/%m/%Y %H:%M"
# => "14/10/2011 17:02"
日付:
#!/usr/bin/ruby -w
date = Time.new
#set 'date' equal to the current date/time.
date = date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display DD/MM/YYYY
puts date
#output the date
上記は、たとえば、10/01/15と表示されます。
そしてしばらくの間
time = Time.new
#set 'time' equal to the current time.
time = time.hour.to_s + ":" + time.min.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display hour and minute
puts time
#output the time
上記は、たとえば、11:33を表示します
次に、それを一緒にするには、最後に追加します。
puts date + " " + time