You can format a date in Ruby using the strftime
method with the appropriate format string. In this case, you can use the following format string:
main.rb24 chars2 lines
Here's an example code snippet:
main.rb132 chars6 lines
In the code above, we first obtain the current date and time using Time.now
. We then use the strftime
method to format the date using the format string "%B %d, %Y %I:%M:%S %p"
, which corresponds to the format you specified. Finally, we print the formatted date to the console.
gistlibby LogSnag