I have this string 2012-06-27 16:17:06
and I want to convert it to GMT format.
How can I do that?
Thanks a lot.
I have this string 2012-06-27 16:17:06
and I want to convert it to GMT format.
How can I do that?
Thanks a lot.
Use gmdate().
Convert your current date format to UNIX timestamp by using strtotime
and then use gmdate($format, $timestamp);
Well, strictly speaking you can not do it. If you do not know in what TZ that date has been generated you can not convert it to another TZ.
If that date came from a DB, probably you can query a date with the original TZ.
$date = new DateTime( "2011-01-01 15:00:00", $original_TZ );
$date->setTimezone( "GMT" );
// Set timeline
$time_line = time() +7200; // <-- this is timeline +2
$h = gmdate('h', $time_line);
$i = gmdate('i', $time_line);
$s = gmdate('s', $time_line);
$time = $h.":".$i.":".$s;
echo $time;
Try this, It will work
$newTZ = new DateTimeZone("Asia/Calcutta");
date_default_timezone_set("Asia/Calcutta");
$GMT = new DateTimeZone("GMT");
$date = new DateTime( "2018-09-20 6:00:00 PM", $newTZ );
$date->setTimezone($GMT);
echo $date->format('Y-m-d H:i:s');
Try this.
$time = '2012-06-27 16:17:06';
echo date("l, F j, Y, g:i a",strtotime($time) ); // assuming gmt format
taken from How do I get Greenwich Mean Time in PHP?