How To Set Your Joomla Time Zone
- Log into your Joomla 3.x administrator Dashboard.
- In the left menu, click the Global Configuration link.
- In the list of tabs towards the top of the page, click the Server tab.
- Under the Location Settings heading, find the Server Time Zone setting.
- Select timezone from dropdown
we can get current time in joomla according to the configuration of joomla server timezone.
Because your host provider have set timezone might be different.
Now if you need to get current time of timezone asia/kolkata which you have set in your joomla backend server configuration.
eg: if your server host provider’s timezone African.
// if Server timezone set as africa/capetown then it will return instance of jdate class with african timezone
eg: $jDate=JFactory::getDate();
$jdate is an object of JDate class of Joomla
JDate:
This is a class that stores a date and provides logic to manipulate and render that date in a variety of formats.
Another way instantiate this class is
$jdate=new JDate();
//get Configuration of joomla site $config = JFactory::getConfig(); // $config is an object of JConfig class of Joomla.this object contain all configuration parameter of this Joomla site.You can access every parameter of configuration by use get method of this object //eg: here we need offset so we can access this like $config->get('offset'); //get instance of JDate class $jDate=JFactory::getDate(); //get offset of joomla it will be return value like asia/kolkata $site_offset = $config->get('offset'); //get instance of joomla JDate Class //if you don't pass timestamps as first argument then it will take default argument value current timestamps,you can pass here formatted time value.Second parameter is timezone if you don't pass this it will be take default argument value of your server timezone. $jdate=JFactory::getDate('now',$site_offset); // first argument now give me current time-stamp you also can pass time-stamp // second parameter is offset i.e. time zone like asia/kolkata $jdate->format('Y-m-d H:i:s',true); //get converted time as your joomla configuration
Supported Framework Version - 3.6.4
Be the first to comment.