A passionate full stack software engineer having 7 years of experience in building scalable enterprise systems. I have worked predominantly with the JVM and Javascript ecosystem but currently exploring Rails. For me, software engineering is all about solving problems in the most optimal way. I am an avid practitioner of clean code practices and love to read about System Design and Architectures. When I am not coding I love to play playstation, read anything about aviation or go out for a long drive and of-course I am foodie by heart.
1 minute read
Previously, to exclude seconds from datetime,
we had to parse datetime using strftime.
Before
Let’s say we have a Product model
and we need to show purchased_at as a date time field excluding seconds.
This is our ProductsController.
And this is how our views/products/show.html.erb would look like.
And this is how it will get rendered on the browser.
After
Now, Rails allows adding a include_seconds option to datetime_field,
using which we can include/exclude the seconds.
This is how a browser renders it.
And suppose we need to include the seconds,
we can pass include_seconds as true.