[wp-hackers] Date/Time and WP

Dobri dyordan1 at ramapo.edu
Wed Jul 17 13:01:24 UTC 2013


Awesome, exactly what I was looking for. Thanks William! Just a sanity check, timestamps are just timestamps and are not affected by timezones, correct? As in, I can still use time(), time()+DAY_IN_SECONDS, etc.?

~Dobri

On Wed, 17 Jul 2013, at 8:56 AM, William P. Davis wrote:

> date_i18n is a fantastic function that will make sure the date and time is returned in the same timezone set in the WP settings
> Sent from my BlackBerry
> 
> -----Original Message-----
> From: Ryan McCue <lists at rotorised.com>
> Sender: "wp-hackers" <wp-hackers-bounces at lists.automattic.com>Date: Wed, 17 Jul 2013 22:48:02 
> To: <wp-hackers at lists.automattic.com>
> Reply-To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Date/Time and WP
> 
> Dobri wrote:
> 
>> From my understanding, when dealing with date and time, WordPress, because of PHP 4 legacy support, sets timezone to UTC and does its own calculations based on the timezone in options. So, when writing plugins, what would be the correct approach to making sure correct timezone is used? Should I use built-in functions like date and somehow specify timezone every time I access them? Or are there any WordPress functions created for that purpose?
> 
> See http://core.trac.wordpress.org/ticket/24730
> 
> Here's how I handle it:
> 
> protected function get_timezone() {
> 	$tzstring = get_option( 'timezone_string' );
> 	if ( ! $tzstring ) {
> 		// Create a UTC+- zone if no timezone string exists
> 		$current_offset = get_option( 'gmt_offset' );
> 		if ( 0 == $current_offset )
> 			$tzstring = 'UTC';
> 		elseif ($current_offset < 0)
> 			$tzstring = 'Etc/GMT' . $current_offset;
> 		else
> 			$tzstring = 'Etc/GMT+' . $current_offset;
> 	}
> 	$zone = new DateTimeZone( $tzstring );
> 	return $zone;
> }
> 
> -- 
> Ryan McCue
> <http://ryanmccue.info/>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list