I need my string "Wed, 26 May 2017 14:00:00 +0800"
to be in format 2017-05-26 14:00:00 +0800
(it's ok to keep it as a string but not mandatory). What's the quickest way?
parse
the string and reformat it via strftime
:
string = 'Wed, 26 May 2017 14:00:00 +0800'
Time.parse(string).strftime('%F %T %z')
#=> "2017-05-26 14:00:00 +0800"
Use strftime
to format date in ruby.
OR
Run Time.now
2017-05-22 15:56:51 +0530
OR
Try below code:
n="Wed, 26 May 2017 14:00:00 +0800"
m=n.to_datetime
m.strftime("%Y-%m-%d %H:%M:%S %z")
output: "2017-05-26 14:00:00 +0800"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With