junkone junkone - 1 year ago 80
Ruby Question

Need to custom format a ruby date object?

how do I format a ruby date as the following?

It looks like the format is 3 characters of month followed by 2 characters of day with a period and a year.

Answer Source
d = Date.parse('14 September 2016')

to get your date object.

d.strftime('%b%d.%Y') #=> Sep14.2016

This will format your date like you wanted. Keep in mind d is not modified, so it is still a Date object. You need to assign the result of the strftime method to any variable.

You can use the downcase method to remove any capitalization.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download