PHP - Server Time In Unreadable Format
I am using this php to write to a text file to show me who has logged in and when:
Code: [Select] <?php $time = $_SERVER['REQUEST_TIME']; $myusername = $_POST['myusername']; $data = "$REQUEST_TIME\n"; $data = "$myusername\n"; //open the file and choose the mode $fh = fopen("logs/login.txt", "a") ; fwrite($fh, $data); fwrite($fh, $time); fclose($fh); ?> The result I get in my text file is: paul 1315919200melody 1315919221tracy&graham 1315919232ed&hannah 1315919251 I would feel more successful if the name of the user were to appear on the next line down but I can live with that but I can't make head nor tale of the date. I want it to say: paul 13:59 13/09/2011 next user 14:00 13/09/2011 and so on I feel I have done very well to even get that far really and wouldn't have been able to yesterday. I am frustrated to have reached the extent of my current understanding. If anyone can tell me where I'm going wrong, that would be great. I hope the php isn't too far off, and you can "read between the lines" as it were to see what I'm trying to do. Paul MOD EDIT: code tags added. Similar Tutorials
Hello All, function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
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! I have the following doubt. When echoing from Server like this: Code: [Select] echo "time=" . time(); I get the time in the following raw format: 1299272294 I would really like to echo it with this format: Tue Mar 1 23:50:00 GMT-0300 2011 Is there a way I could do that? Really looking forward for some help on this one, Thanks a lot in advance! Cheers! Hi, The hosting provider for my domain confirm me that the server time is in EST (UTC-5). They also sent me a grab supporting that Code: [Select] server time is now: ---------------------- Sun Nov 7 02:20:01 EST 2010 ------------------- But when I use the following code, the output I get is has 1 hr difference (UTC-6) echo date("d M, Y h:i:s A",time()); Output==> 07 Nov, 2010 01:20:01 AM But it suppose to give the same time as the server, ryt? Can anybody please explain? Thanks, Hi everyone I have a column in an sql database which stores time in minutes. I'm trying to turn these minutes into this kind of format: 1:00pm 12:30am 6:15pm I looked on W3C and there was the %r which seemed to format this way but I cant get it to work >.< Code: [Select] $time1=$f3/60; $time2= date_format($f4, '%r'); Does anyone know how to achieve this? THANKS!!! I used the following code to convert the length in seconds to min:second format $sec=$duration % 60; if ($sec=="0"){ $min=$duration/60; $duration=''.$min.':00'; }else{ $min=(($duration-$sec)/60); $duration=''.$min.':'.$sec.''; } everything is OK, but it shows 35:5 instead of 35:05. I mean it disregards the first 0 when the second is 1-digit. I want the current date to be displayed in this format: year-month-day hr:min:sec Suggest me some functions or codings I have the time time now viewed as 17:11. The time $Start_Time is 17:00. The time $End_time is 18:00. Can I use this to check if time is in between starttime and endtime? Or do I have to convert it to other formats before it understand that I'm comparing it as times and not just numbers? if($Start_Time < $Now_time && End_Time > $Now_time){ } I'm trying to make $time be a variable with the current time and I want it to have the same format as mysql. I can't figure out what I am doing wrong here Wrror: Warning: date_format() expects parameter 1 to be DateTime, integer given Code: [Select] $time = date_format(time(),'Y-m-d H:i:s'); How can I format my time value (initially created by using time()) to ISO 8601 so it can be used in the format described he http://timeago.yarp.com/ 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.
Hi, I have noticed on my print order section in my cart that the date/time is in US format ie. there is an entry that calls up "date_purchased" and places this in the following format %Y-%m-%d %H:%M:%S I have searched all the text in my online shop and I have located the code i believe is responsible under \includes\classes\nusoap.php This is in the following entry return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec); My question is can i change this code to either of the following without causing any damage else where in the site? I am not sure if it needs the %H:%M:%S', $sec entry here for anything??? Can i do.. return strftime ('%d-%m-%Y %H:%M:%S', $sec) or return strftime ('%d-%m-%Y ) without it causing issues in the code? Many Thanks, Hi, I'm trying to insert this $inceptiondate = date("Y-m-d 12:00:00"); to the database, the Y-m-d does make it to database, but the 12:00pm doesn't. Whenever it reaches the database, it becomes 00:00:00 Where did I got wrong? Thanks Hello there, I was curious about PHP's 'time()', now is there any way to parse that into a human readable version e.g 7:53 PM, because I'm unsure on how to work with the time function since it's returned in the unix format, thanks again in advance for your help guys. I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. I know I can get the current time using time() $time=time(); Can do I do some kind of manipulation using strtotime() and store in the database in datetime format? I'm not sure if this is the place to ask this question, but please advise <?php echo "time=" . time(); ?> does the time change when viewing in other countries? E.g. Is echo the same when viewed in China, US, New Zealand? Thanks! I just recalled using date(); time() for lots of things in my database, including post times etc. At first I simply assumed this used server time or something, but when I changed my PC's time, it changed ! Now, shortly after this I simply assumed this was because of me using a localhost? But I am not certain anymore.. If I would place this online, would date() and time() return you server time or user time? I couldnt find it on google =-( 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()); Is there a way to run a check on the server to see how long it takes for the page to get built, then print it to the screen?
I tried searching for it online for a few minutes, but it wasn't able to be found. All I'm finding on there is how to optimize the pages, but I want a simple time check performed on the page loading
Is there any way to have a field that will update any time its row is updated?
My situation is that I will have multiple devices writing to a database, and in one case the time that is being kept track of is important. And the devices writing to the database are a bit difficult to keep accurate times on, so instead of writing the time from the devices themselves, I was hoping I could just have a field update itself. I know it can be done on INSERT, but I do not want to do an INSERT every time.
Thanks!
|