[英]how to convert the date format from dd-mmm-yyyy to yyyy-mm-dd in ruby on rails
I am uploading the csv file. 我正在上传csv文件。 The csv file contains the date format in
dd-mm-yyyy
format. csv文件包含
dd-mm-yyyy
格式的日期格式。 How can I change it to yyyy-mm-dd
format. 如何将其更改为
yyyy-mm-dd
格式。 I also tried to_date function but it gives the error as invalid date. 我也尝试了to_date函数,但是它给出了错误,因为它是无效的日期。
You can do this by below code 您可以通过以下代码执行此操作
require 'date'
date = DateTime.parse("22-02-2019")
formatted_date = date.strftime('%Y-%m-%d')
output 产量
"2019-02-22"
please go through with this document https://www.rubydoc.info/stdlib/core/Time:strftime you will find out the different formatting style 请仔细阅读本文档https://www.rubydoc.info/stdlib/core/Time:strftime,您将了解不同的格式设置样式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.