Change string in a date format to another format

前端 未结 4 1920
独厮守ぢ
独厮守ぢ 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:32

    strptime parses the string representation of date with the specified template and creates a date object.

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

提交回复
热议问题