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.

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.

Read Also:  VueJS Textarea maxLength Remaining Character Count

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 :

Read Also:  how to insert date in mysql using php?


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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *