How to convert date according to specific locale in Magento 2?

Sometimes we need to convert date formate to locale. We can use \Magento\Framework\Stdlib\DateTime\TimezoneInterface class to convert dare according to locale. Using Object Manager: $date = new \DateTime('2019-11-21'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $formatDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\TimezoneInterface') ->formatDate( $date, \IntlDateFormatter::FULL, false ); Using Dependency Injection: namespace MagePrince\Testing\Model; class FormatDatLocale { private $timezoneInterface; public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezoneInterface ) {…

Continue Reading How to convert date according to specific locale in Magento 2?

How to set custom date format in Magento 2?

We can use Magento\Framework\Stdlib\DateTime\DateTimeFactory class to set custom date format. During development, we need to set a custom date format to display in the frontend or need to pass the custom data to APIs. So here is the code to set custom date format. namespace MagePrince\Testing\Model; class FormatDate { private $dateTimeFactory; public function __construct( \Magento\Framework\Stdlib\DateTime\DateTimeFactory…

Continue Reading How to set custom date format in Magento 2?

How to use Search Criteria for the custom collection in Magento 2?

In this article, I will show you, how you can use Search Criteria in the custom collection. Search Criteria is an implementation of the SearchCriteriaInterface class that allows you to build custom requests with different conditions. You can read more at devdoc for Search Criteria Searching with Repositories 1. Here we use getList() method to get custom…

Continue Reading How to use Search Criteria for the custom collection in Magento 2?