PHP - Format Time To Iso 8601
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 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"; */
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 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'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'); 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){ } 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 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.
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. 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? Hi all, I am currently making a website that has e-custom functions and a back end for the client. I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change I got no issue with the png/gif type for upload/resize function since this type already transparent background but my major problems is how to deal with jpeg/jpg image type which is their background was not a transparent...so is it possible I can change/ convert to png/gif type upon successful of uploading image...so the new final image will be png/gif type with transparent background...is it doable...I am not even sure it is possible...? Thanks for any help.. 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 Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } 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. I 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!
What are the differences and implications of UTC time and Zulu time? <?php function getArr(string $time):array { $dateTime = new \DateTime($time); return [ 'time'=>$time, 'timestamp'=> $dateTime->getTimestamp(), 'dateTime' => $dateTime ]; } $arr = getArr('2020-08-05'); $arr_z = getArr('2020-08-05T00:00:00Z'); print_r($arr); print_r($arr_z); echo('equal timestamps: '.($arr['timestamp'] === $arr['timestamp']?'true':'false'));
Array ( [time] => 2020-08-05 [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) Array ( [time] => 2020-08-05T00:00:00Z [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 2 [timezone] => Z ) ) equal timestamps: true
|