PHP - Php Date And Time Function Is Not Showing Correct Time On My Local System
PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel Similar TutorialsI am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! Hi all, I am working on my PHP script to set up the date with the time for the autoresponder so I can send out the emails at the specific time. I need some help with set up the correct day date with the time, because on my code when I have two different times `06:00` and `20:00`, as both of them will show the time with the current day date, e.g: 28-11-2019. I find that my code have set up the date as incorrect because the time I have `06:00` which it should have set up with the next day date, e.g 29-11-2019 instead of 28-11-2019 and the time `20:00` should set up with the current day date as my current time is `15:26pm` right now.
2019-11-25 06:00
06:00
$auto_responders = $link->prepare('SELECT * FROM autoresponder WHERE campaign = ? ORDER BY id ASC'); $auto_responders->execute([$campaign]); $auto_responders->setFetchMode(PDO::FETCH_ASSOC); $auto_responders = $auto_responders->fetch(PDO::FETCH_ASSOC); $get_time = $auto_responders['send_time']; if ($get_time >= strtotime('00:00')) { $autoresponder_date = date('Y-m-d', strtotime($get_time . ' +1 day')); } else { $autoresponder_date = date('Y-m-d', strtotime($get_time)); } $send_time = $autoresponder_date . ' '. date('H:i ', strtotime($get_time));
Can you please show me an example how I can set up the day date for the time `06:00` and `20:00` as if I have the time is `06:00` then check if the time have passed before I could do anything to send the email and it is the same for the time `20:00:00`? Thank you.
PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. Hey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. Hi there, what I have been trying to do is add some additional logic.. My problem is I want to stop displaying the month and day after the year 2000? I know I need to add an if and else statement but this is my first actual project and I am a little stuck.. here is the page, it's a plugin for a timeline http://www.llandover...oject-timeline/
And the file is attached below.. any help would be appreciated. The plugin code was too long to just post in here, didn't want to cause any slow loading issues for people on a slow connection.. Thanks and I appreciate any help.
Attached Files
annual_archive.php 18.15KB
5 downloads hello i got this small function i`m working on to get the date of a month something like get current date - 1 but not sure how to handle jan month can someone help me please ? $month = date('m') - 1; $date_startt = date('Y').'-'.$luna.'-01'; $timestamp_start = strtotime($data_start); First, I would like to say when i tried to recover my account from this website, I took me 10 attempts to get the captcha right and then finally it said it sent me an email to my gmail account. I checked spam folder and everything there was no such email from this site. Then I decided to create a new account, well, it took me another 10 attempts to get the captcha right and finally when it was submitted, the page was loading for around 3 minutes before it signed me in.
My question is about the php date() function. It accepts a format to display a time. In the following example I use F for full representation of month, d for 2-digit day of month with leading zeros, Y for full year, g for 12-hour format without leading 0s, s for seconds and A for meridiem. It uses the correct format, but it gives me the wrong time. My local time is 4:43 and it prints out 4:12:
<?php echo "<p>order processed on " . date("F d, Y g:sA") . "</p>"; ?> Why is it 30 minutes behind? I think it is unusual but i dont know to fix it. when my computer clock shows 16: 13 hours , date() reuturns 10:43:16 . My systems time zone is +5.30 GMT. how does date() subtracts 5.30 hrs from the system time? OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks. im wondering is there any easy way to echo server time and local time... without converting them from unix to timestamp i have found thi code, but i cant tell is it server or local Code: [Select] echo date("H:i" ,time()); Hey, I'm trying to code a page which is supposed to bring up the time of a person's computer. Is this possible without majorly complicated coding? I'm good with GMT offsets and stuff but I don't know how to get the time of a person's computer. I don't want other stuff, just the time so I can edit the time based on where they are. I don't know if I'm making sense so here's an example... If someone does a forum post at 2pm Sydney time but it's 5pm Perth time. How can I make it so that someone in Perth sees 5pm but someone in Sydney sees 2pm...without them manually telling me their timezone? I read about using IP addresses but don't know much (Ok anything) about this , any hints or good sites to view would be appreciated? Or the answer if it's not too complex. Preferably I'd like to get the time in the 11 digit "time()" format so I can use it in tables and translate it with an existing function. IceKat I am trying to get local date/time. In my php file I am setting my timezone using $timezone = "America/Toronto"; putenv ('TZ=' . $timezone); Then I use the following to get current date and time print_r (getdate()); but my date displays in GMT, What am I doing wrong? As in the code above I am in Toronto and I need EST. I have all the dates stored in my database as UTC and I want to retrieves these UTC date/time to show the local time zone. So, example, If I live in New York, I want it to show east coast time zone and not the Universal Time. Any idea? Hello, I got myself a RSS feed for my posts, which can be seen he codexplained.tk/feed/rss.php This is the code used for it: Code: [Select] <?php // header header("Content-Type: application/xml; charset=UTF-8"); require("../widgets/functions.php"); // Make a MySQL Connection connectToDB(); echo ' <rss version="2.0"> <channel> <title>Codexplained RSS Feed</title> <link>http://www.codexplained.tk</link> <description>For all your coding needs</description> <language>en</language> '; $query = "SELECT * FROM posts ORDER BY Id DESC LIMIT 15"; $res = mysql_query($query); $num=mysql_numrows($res); $i = 0; while ($i < $num) { $subject=mysql_result($res,$i,"Subject"); $id=mysql_result($res,$i,"Id"); $content=mysql_result($res,$i,"Content"); $content = str_replace("<br />", "\n", $content); $content = str_replace("<?php", "<?php", $content); $content = str_replace("?>", "?>", $content); $content = htmlentities($content); $content = substr($content, 0,400); echo ' <item> <title>'.$subject.'</title> <link>http://www.codexplained.tk/index.php?postDetails='.$id.'</link> <description>'.$content.'</description> </item>'; $i++; } echo ' </channel> </rss> '; ?> Now, I wish to know how to make the time display correctly, and not just according to refresh date. I tried something with <pubDate> but I couldn't figure it out. Help would be appreciated! Hello Everyone, I am on windows server and In my ini file server time zone declared as below
[server_settings] but my application installed on another timezone eg: 'America/Los_Angeles' time zone. using date_default_timezone_get() i am always getting Europe/London timezone as it's declared in ini file. How to get local timezone(wherever application is installed) here? Thanks Krish How to output a MySQL timestamp field to correct local time with daylight saving with PHP?
Local time is set in php.ini with: date.timezone = "Europe/London"
Confirmed set with: <?php echo date_default_timezone_get(); ?>
But when I echo the timestamp field it does not display correct UK time for the record (an hour behind correct UK time).
<?php echo date('jS F Y - g:ia', strtotime($row['Date'])); ?>
When I echo the current time, the hour is what it is plus one: echo date("h:i:s:A"); Real time is 3:46:33 Would display 4:46:33 What is wrong here? Hi, I'm inserting hours and minutes per user into a database where they have their own fields. (userid, hours, mins) I've a small issue when displaying the data. When I run my query I sum the total hours and minutes per user which results in data such as the following userid1 - 2 hours 15 mins userid2 - 1 hour 100 mins The query orders by hours and then mins desc When I'm displaying the data (as I'm looping through the results array) I perform a calculation to convert the mins to hours so it now reads userid1 - 2 hours 15 mins userid2 - 2 hours 40 mins so the webpage displays userid1 first when i want userid2 to be the first record displayed (Hours desc) Can anyone recommend a solution to this ? Will I need to create another table and update it as hours and minutes are being entered and display results from that table instead ? Can I order the data after I carry out the mins to hours calculation ? many thanks in advance for any suggestions.... tmfl Hi, i am thinking of creating a text based game mmorpg using php/mysql etc... I know that a lot of these types of games use a tick based system, but i want it to be realtime, the only game i cna find that uses this is Torn, does anyone know how they make it realtime? I know that ticks can be controlled by cronjobs, but how about realtime? The problem is that the game might involve the player building a house, in a tick based system it could be easy to manage by saying the house will take 3 ticks to complete, but i want the house to be like in 10 minutes of 32 minutes, how can i do this. Someone said to check whenever the player next logs in to check if the house has finished and then say it has been built, but seeing as it is an mmorpg it could affect everyones gameplay, not just the person building it, so this will not work. Thanks and sorry if this is a bit confusing. hello dear php-experts i run opensuse 13-2 and i am very very happy the time does not get displayed correct. it falls back to UTC all day. What can i do. i have had look at the documents here https://en.opensuse....uring_the_clock https://tr.opensuse....T_Date_and_Time how to set up correct to the local time - note i live in GERMANY near francfurt |