Skip to content

Instantly share code, notes, and snippets.

View aaronmarton's full-sized avatar

Aaron Marton aaronmarton

View GitHub Profile
@codearachnid
codearachnid / wp_convert_to_timezone.php
Last active September 19, 2023 17:21
Recently was working on importing dates into WordPress and needed to convert the date to the current site timezone. Because WordPress may not give you the timezone string if an UTC offset is set I modify the datetime vs change the timezone.
<?php
/**
* wp_convert_to_timezone useful for adjusting an imported DateTime to your site GMT/UTC offset
*
* @link http://www.php.net/manual/en/timezones.php Accepted $timezone strings
* @link http://www.cs.tut.fi/~jkorpela/iso8601.html Reason for default return as ISO 8601
*
* @param string $datetime
* @param string $timezone default GMT