公告
财富商城
积分规则
提问
发文
2019-07-04 04:33发布
Juvenile、少年°
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT format. How can I do that?
2012-06-27 16:17:06
Thanks a lot.
// 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;
PHP's DateTime Object is a good choice:
$GMT = new DateTimeZone("GMT"); $date = new DateTime( "2011-01-01 15:00:00", $GMT ); $date->setTimezone( $newTZ ); echo $date->format('Y-m-d H:i:s');
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" );
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');
Use gmdate(). Convert your current date format to UNIX timestamp by using strtotime and then use gmdate($format, $timestamp);
strtotime
gmdate($format, $timestamp);
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?
最多设置5个标签!
PHP's DateTime Object is a good choice:
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.
Try this, It will work
Use gmdate().
Convert your current date format to UNIX timestamp by using
strtotime
and then usegmdate($format, $timestamp);
Try this.
taken from How do I get Greenwich Mean Time in PHP?