How do I get the current date and time in PHP

0 votes

Which PHP function can return the current date/time?

Feb 16 in Others by Rahul
• 8,980 points
17 views

1 answer to this question.

0 votes

The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions are called.

If I am in Melbourne, Australia so I have something like this:
 

date_default_timezone_set('Australia/Melbourne');

Or another example is if I am in LA - US:
 

date_default_timezone_set('America/Los_Angeles');

You can also see what timezone the server is currently in via:
 

Date_default_timezone_
get();

So something like:
 

$timezone = date_default_timezone_get(); 
echo "The current server timezone is: " . $timezone;
So the short answer for your question would be:
// Change the line below to your timezone! date_default_timezone_set('Australia/Melbourne'); $date = date('m/d/Y h:i:s a', time());

Then all the times would be to the timezone you just set. Hope this answers your question.

answered Feb 16 by Aditya
• 7,280 points

Related Questions In Others

0 votes
2 answers

How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

answered Aug 12, 2020 in Others by Steve
• 200 points
616 views
0 votes
0 answers

How do I determine the size of my array in C?

How do I determine the size of ...READ MORE

May 1 in Others by Kichu
• 16,850 points
17 views
0 votes
2 answers

How do neural networks used in AI and deep learning learn?

A neural network is a hardware or software ...READ MORE

answered Apr 8, 2019 in Others by SA
• 1,050 points
363 views
0 votes
1 answer

How do I get a cheap domain name? - web hosting

Many web hosting companies like amazon's lighsail ...READ MORE

answered Oct 28, 2019 in Others by Yesha
311 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
509 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
9,008 views
0 votes
1 answer

Failure uploading Image on AmazonS3 with PHP SDK

Try this, I took it out from ...READ MORE

answered May 4, 2018 in AWS by Cloud gunner
• 4,650 points
2,028 views
0 votes
1 answer

Trying to call AWS API via PHP

Try using AWS SDK for PHP, Link ...READ MORE

answered Jun 6, 2018 in AWS by Cloud gunner
• 4,650 points
961 views
0 votes
1 answer

How to get current time and date in Android

In order to get the current date ...READ MORE

answered Feb 23 in Others by Aditya
• 7,280 points
84 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP