Ruby

内容

Rubyで日付を取得するにはdateライブラリを読み込んだ上でDateクラスのオブジェクトを作成したうえでstftimeメソッドで必要なフォーマットに変換できます。

記述

require 'date'

thisyear = Date.today
thismonth = Date.today
thisdate = Date.today                                                                                                                                                        
sd1 = thisyear.strftime("%Y")
sd2 = thismonth.strftime("%m")  
sd3 = thisdate.strftime("%d")

print #{sd1}/#{sd2}/#{sd3}

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-06-30 (木) 01:40:11