Hello Guys, I Have Prob $now = new DateTime('now'); $now->setTimezone(new DateTimeZone('Asia/Karachi')); echo $now->format('c'); PHP: This code show me date something like this 2015-08-04T03:49:25+05:00, Thats Correct, But actually I need timestamp, with Asia/Karachi timezone, So when I change echo $now->format('c'); to echo $now->getTimestamp(); output is 1438642165, But when I convert this timestamp to readable time, I got this 2015-08-03T22:49:25+00:00, which is incorrect, please help me to get correct timestamp Sorry for bad English
You are probably converting that timestamp incorrectly or without reference to the timezone you have: $now = new DateTime('now'); $now->setTimezone(new DateTimeZone('Asia/Karachi')); echo $now->format('c').PHP_EOL; $time = $now->getTimestamp(); echo $time.PHP_EOL; $now = new DateTime(); $now->setTimestamp($time); echo $now->format('c').PHP_EOL; /* 2015-08-04T05:01:48+05:00 1438646508 2015-08-03T17:01:48-07:00 */ Code (markup): You need to insure that the timezone is set before you output the time like so: $now = new DateTime('now'); $now->setTimezone(new DateTimeZone('Asia/Karachi')); echo $now->format('c').PHP_EOL; $time = $now->getTimestamp(); echo $time.PHP_EOL; $now = new DateTime(); $now->setTimezone(new DateTimeZone('Asia/Karachi')); $now->setTimestamp($time); echo $now->format('c').PHP_EOL; /* 2015-08-04T04:58:28+05:00 1438646308 2015-08-04T04:58:28+05:00 */ Code (markup): You can see that the timestamp you have reflects the timezone you have set.