How to display the current date in “mm/dd/yyyy” format in Rails

前端 未结 4 1708
猫巷女王i
猫巷女王i 2020-12-08 12:48

In my view I want to display the current date in \"mm/dd/yyyy\" format.

4条回答
  •  情歌与酒
    2020-12-08 13:19

    I think you can use .strftime:

    t = Time.now()
    t.strftime("The date is %m/%d/%y")
    

    This should give "The date is 09/09/10". See here for a great list of the format codes for .strftime.

提交回复
热议问题