convert string to specific datetime format?

前端 未结 7 831
孤城傲影
孤城傲影 2020-12-24 11:21

String

\"2011-05-19 10:30:14\"

To

Thu May 19 10:30:14 UTC 2011

How can I convert specific string to this

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 12:20

      <%= string_to_datetime("2011-05-19 10:30:14") %>
    
      def string_to_datetime(string,format="%Y-%m-%d %H:%M:%S")
        DateTime.strptime(string, format).to_time unless string.blank?
      end
    

提交回复
热议问题