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
28 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
722 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
• 19,040 points
25 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
378 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
328 views
0 votes
0 answers

What php timezone I use for San Francisco, California, United Stated

What PHP time zone can I use ...READ MORE

May 27 in PHP by Kichu
• 19,040 points
22 views
0 votes
0 answers

Convert one date format into another in PHP

How can I convert one date format ...READ MORE

Jun 20 in PHP by Kithuzzz
• 320 points
4 views
0 votes
0 answers

How to calculate the difference between two dates using PHP?

I have two dates on the form: Start ...READ MORE

Jun 24 in PHP by narikkadan
• 10,840 points
6 views
0 votes
0 answers

php convert date to mktime function

I posted a date input $_POST['date'] with format 2013/11/22 and time $_POST['time'] with ...READ MORE

Jun 27 in PHP by narikkadan
• 10,840 points
6 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
201 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