PHP wordpress get timezone Example – MySQL

Today, We want to share with you PHP wordpress get timezone.In this post we will show you wordpress get website time, hear for wordpress strtotime timezone we will give you demo and example for implement.In this post, we will learn about How to get WordPress Time Zone setting? with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

PHP wordpress get timezone

There are the Following The simple About Set correct timezone in PHP Date function Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to get current date and time in WordPress?, so the Get GMT Offset from ‘gmt_offset’ option in wordpress is used for this example is following below.

How to get WordPress Time Zone setting?

Get gmt_offset

<?php echo get_option('gmt_offset'); ?>

Get timezone_string

<?php echo get_option('timezone_string'); ?>

How to get date using timezone saved in options?

$timezone_string = get_option('timezone_string');

wordpress – current timezone using php

    if (date_default_timezone_get()) {
        echo 'Your Current Time in  ' . date_default_timezone_get() . ':';

wp timezone and gmt offset

function set_defaults_for_datetime() { 
	if (($timezone_str = get_option ('timezone_string') ) and (!empty($timezone_str))) {
			$fulltimezone = timezone_open($timezone_str);
	else {	
		if (($gmt_offset = get_option ('gmt_offset')) and (!(is_null($gmt_offset))) and (is_numeric($gmt_offset))) {
			$timezone_str = $this->fetch_offset_from_zone($gmt_offset);
			$fulltimezone = timezone_open($timezone_str );
		else {
			$fulltimezone = timezone_open(date_default_timezone_get()); // this will give UTC as wordpress  ALWAYS uses UTC
	return $fulltimezone;
function fetch_offset_from_zone($offset) {

	$timezones_list = calc_offset_from_tz_list ();	

	$timezones_list = array(
		'8:30' => 'Asia/Harbin',
		'8:45' => 'Australia/Eucla',
		'10:30' => 'Australia/Lord_Howe',
		'12:45' => 'Pacific/Chatham',
		'13:45' => 'Pacific/Chatham',

	$intoffset = intval($offset);
	$stroffset = strval($intoffset);
	if (isset($timezones_list[$stroffset])) 
		return ($timezones_list[$stroffset]);
		return false;
function calc_offset_from_tz_list () {
	$list_time_zone = timezone_identifiers_list();
	//echo '<pre>'.print_r($list_time_zone, true).'</pre>';
	$utc = new DateTimeZone('UTC');
	$now = new DateTime("now", $utc);
	foreach ($list_time_zone as $fulltimezone) {
		$allObject = new DateTimeZone($fulltimezone);
		$off = $allObject->getOffset($now)/(60*60); 
		$hour = (int) $off;
		$decimal = $off - $hour; 
		$floarhour = $decimal * 60;
		$offsets[$fulltimezone] = (string) $hour ;
		if ($floarhour > 0) $offsets[$fulltimezone] .= ':'. (string) $floarhour  ;
	//echo '<pre>'.print_r( $offsets, true).'</pre>';
	$dtaa_timeZonePrt =array_flip($offsets);
	echo '<pre>'.print_r( $dtaa_timeZonePrt, true).'</pre>';
	return $dtaa_timeZonePrt;

Get TimeZone Offset From UTC


Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about wordpress get mysql date.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Server-side processing Laravel DataTables
  2.   Simple JQuery Preloader With CSS And Image
  3.   OneDrive Move copy create delete file folder
  4.   REST API CRUD Example in PHP with MySQLi
  5.   jQuery Ajax Get JSON in Laravel Example
  6.   PHP laravel open new tab Example Tutorial
  7.   Simple Laravel Form Validation Example
  8.   Magento 2 How to solve one or more indexers with Reindexing using Command
  9.   Simple Laravel Query Dumper Getquerylog
  10.   Nodejs Login and Registration with PHP MySQL and SQLite Example