「Ruby」Time.newで現在時刻を取得するサンプル

2020年12月14日

説明
new -> Time
now -> Time
現在時刻の Time オブジェクトを生成して返します。

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
timeA = Time.new
puts "現在時刻 : " + timeA.inspect
# Time.now 動作同じ
timeB = Time.now
puts "現在時刻 : " + timeB.inspect
#!/usr/bin/ruby # -*- coding: UTF-8 -*- timeA = Time.new puts "現在時刻 : " + timeA.inspect # Time.now 動作同じ timeB = Time.now puts "現在時刻 : " + timeB.inspect
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
timeA = Time.new
 
puts "現在時刻 : " + timeA.inspect
 
# Time.now 動作同じ
timeB = Time.now
puts "現在時刻 : " + timeB.inspect

実行結果
>ruby test.rb
現在時刻 : 2020-12-14 10:30:00 +0900
現在時刻 : 2020-12-14 10:30:00 +0900

Ruby

Posted by arkgame