How do I get the current date and time in PHP

0 votes

Which PHP function can return the current date/time?

Feb 16, 2022 in Others by Rahul
• 9,680 points
714 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, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
0 answers

How can I get the intersection, union, and subset of arrays in Ruby?

I want to develop many methods for ...READ MORE

Aug 8, 2022 in Others by krishna
• 2,820 points
505 views
0 votes
1 answer

In excel how do I reference the current row but a specific column?

Put a $ symbol in front of ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,600 points
1,923 views
0 votes
1 answer

Excel - How can I get the average of cells where the value in one column is X and the value in another column is Y?

Use AVERAGEIFS ... =AVERAGEIFS(C2:C13,A2:A13,"Yellow Typ ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 63,600 points
1,399 views
0 votes
1 answer

How do I get an Excel range using row and column numbers in VSTO / C#?

Use: int countRows = xlWorkSheetData.UsedRange.Rows.Count; int countColumns = xlWorkSheetData.UsedRange.Columns.Count; object[,] ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,600 points
1,755 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, 2022 in PHP by Kichu
• 19,040 points
610 views
0 votes
0 answers

Convert one date format into another in PHP

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

Jun 20, 2022 in PHP by Kithuzzz
• 38,000 points
304 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, 2022 in PHP by narikkadan
• 63,600 points
661 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, 2022 in PHP by narikkadan
• 63,600 points
476 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, 2022 in Others by Aditya
• 7,680 points
2,140 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP