I have a contact us form, I want to set echo the time zone in my "abc.phtml" file on the basis of the visitor visits the page into the contact us form, it should display there and in my contact sent mail, i will understand the timezone of my visitor who filled my "contact us" form. Kindly tell me some way how can i achieve this by following all the magneto rules.
Using Ip address and some geo-location it may be possible but i want to know the exact way or to the point solution for this. Please help in this matter. timezone get magento In the image you can BST written there, we can have IST or EST or GMT etc, i want it according to visitor's location.


1 Answer 1


We can purchase an api from here https://www.ip2location.com/database/ip2location or any other place, if we give the ip address of visitor as a request then it will response with "timezone" and using the timezone easily we can get the local time of visitor.
In US we have around 25+ timezones..
Here in this Example, I am setting the time zone using this php method date_default_timezone_set() then reading the time of every 25 places. Some of my finding here

     $countryCode="US";//this one is for United States of America //2 letter code 
     $timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);

     date_default_timezone_set($timezone[ $i ]);    
     $DateAndTime = date('m-d-Y h:i:s a', time());  
     echo "The current date and time in are $DateAndTime.\n";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.