Change string in a date format to another format

前端 未结 4 1883
独厮守ぢ
独厮守ぢ 2021-01-03 04:42

I have a string like this (YYYYMMDD):

20120225

And I want to have a string like this (MM/DD/YYYY):

02/25/

4条回答
  •  借酒劲吻你
    2021-01-03 05:17

    Parsing it then formatting it is the best solution:

    Date.parse("20120225").strftime("%m/%d/%Y")  #=> "02/25/2012"
    

提交回复
热议问题