我想显示sql表中的数据,数据类型是datetime(6),数据大小为6个字节。现在,当我在带有输入标签和类型文本的html表中显示数据时,我得到带有尾随零的日期时间格式。我想显示日期时间格式而不尾随零。我在下面显示代码。
收集数据的输入表单上的代码。
<li>
<label for="date-time">Access Date And Time</label>
<input name="date-time" type="datetime-local" id="date-time"/>
</li>
&#13;
这是显示数据的代码。
<?php
include('/templates/header.php');
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "datacentre"; // Database name
$tbl_name = "data_centre_users"; // Table name
$server_name = "localhost";
// Create connection
$con = new mysqli($server_name, $username, $password, $db_name, 3306);
if($con->connect_error){
die("Connection failed: ".$con->connect_error);
}
// Check connection
if($con->connect_error){
die("Connection failed: ".$conn->connect_error);
}
$sql = "SELECT * FROM $tbl_name";
$result = $con->query($sql);
?>
<section id="sidebar">
</section>
<section id="content">
<div id="scroll-table">
<table >
<caption>
List data from mysql
</caption>
<tr>
<th class="center"><strong>ID</strong></th>
<th class="center"><strong>FirstName</strong></th>
<th class="center"><strong>Lastname</strong></th>
<th class="center"><strong>Request</strong></th>
<th class="center"><strong>Purpose</strong></th>
<th class="center"><strong>Description</strong></th>
<th class="center"><strong>Booking Time</strong></th>
<th class="center"><strong>Access Time</strong></th>
<th class="center"><strong>Exit Time</strong></th>
<th class="center"><strong>Approved</strong></th>
<th class="center"><strong>Approved By</strong></th>
<th class="center"><strong>Update</strong></th>
<th class="center"><strong>Delete</strong></th>
</tr>
<?php
if($result->num_rows > 0){
// output data of each row
while($rows = $result->fetch_assoc()){ ?>
<tr>
<td class="center"><?php echo $rows['id']; ?></td>
<td class="center"><?php echo $rows['fisrt_name']; ?></td>
<td class="center"><?php echo $rows['last_name']; ?></td>
<td class="center"><?php echo $rows['request']; ?></td>
<td class="center"><?php echo $rows['purpose']; ?></td>
<td class="center"><?php echo $rows['description']; ?></td>
<td class="center"><?php echo $rows['booking_time']; ?></td>
<td class="center"><?php echo $rows['access_time']; ?></td>
<td class="center"><?php echo $rows['exit_time']; ?></td>
<td class="center"><?php echo $rows['approved']; ?></td>
<td class="center"><?php echo $rows['approved_by']; ?></td>
<td class="center" ><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td>
<td class="center" ><a href="delete.php?id=<?php echo $rows['id']; ?>">delete</a></td>
</tr>
<?php
}
}
?>
</table>
</div>
</section>
<aside></aside>
<?php
$con->close();
include('/templates/footer.php');
?>
&#13;
这是网页。
答案 0 :(得分:1)
$timestamp = strtotime($rows['booking_time']);
echo date('Y-m-d H:i:s',$timestamp);
应格式化日期