Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 763
  • Last Modified:

How to get sys date/time in GMT-5 in PHP

Hello!

I want to return a string in that format:
YYYY-MMM-DD H24:MM:SS
(2007-July-20 10:30:00)

I don't know in which time zone the server is set but I want the result to be in GMT-5 time. How do I do this?
0
mychel_normandeau
Asked:
mychel_normandeau
  • 2
2 Solutions
 
cpulseCommented:
One way is this:

$dt = date('Y-F-d H:i:s', gmdate() - 3600 * 5);
0
 
milanmkCommented:
<?php
putenv('TZ=Etc/GMT-5');
print date('Y-M-d h:i:s');
?>

If you want a timezone of some specific city then you can use like putenv('TZ=Asia/Calcutta') also.
0
 
mychel_normandeauAuthor Commented:
If I use
date('Y-M-d h:i:s', time() - 18000)
would it work on any server config?

Doest time() gives the current GMT0 unix timestamp?
0
 
milanmkCommented:
time() defaults to current local time.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now