我在表格中有一列列出了每行的创建日期,列显示日期如2018 Mar 28
,日期搜索选择日期类似于2018-03-28
如何将上述每种格式转换为另一种格式:
2018 Mar 28 to 2018-03-28
和
2018-03-28 to 2018 Mar 28
由于
答案 0 :(得分:3)
来回:
▶ ["2018 Mar 28", "2018-03-28"].zip(["%F", "%Y %b %d"]).
▷ map { |date, format| Date.parse(date).strftime format }
#⇒ ["2018-03-28", "2018 Mar 28"]
Date#strftime
的所有可能格式化程序。
答案 1 :(得分:0)
'2018 Mar 28'.to_date.to_s
或Date.parse('2018 Mar 28').to_s
应该反向工作,您可以执行Date.strptime('2018-03-28', '%Y-%m-%d')
答案 2 :(得分:0)
这可能是一个重复的问题,但是:
您可以使用<div class="flex-container">
<div class="profile-picture image">
</div>
</div>
<div class="profile-name">
<p>cole gwoz</p>
</div>
<div class="user-name">
<p>colegwoz</p>
</div>
<div class="follow-button-position">
<button class="follow-button">Follow</button>
</div>
<div class="flex-container">
<div>
<img src="https://www.dropbox.com/s/4c05cegbonfqo5k/Photo%202018-03-03%2C%202%2020%2022%20PM.jpg?raw=1"></div>
<div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
<div><img src="https://www.dropbox.com/s/8dtg60sbha99x2o/Photo%202018-02-05%2C%209%2026%2043%20AM.jpg?raw=1"></div>
<div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
<div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
</div>
请参阅: https://apidock.com/ruby/DateTime/strftime
和 https://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html#method-i-strftime