0

我正在创建一个 HTML 表格,它以两种不同的方式显示员工时间的分配。第一种方式,是一个ajax更新的队列,显示当前员工的行踪,完成。

第二种是用户可以输入过去“分配”的表格。现在,因为我的业务是 24/7,我决定将所有时间存储为 mysql 中的日期时间,所以我可以得到以下区别:

2013-04-11 21:59:292013-04-12 01:52:29

这是正在填写的表格:

 <form action="mafs.php" method="post" id="form1" name="form1" class="">     

                    <table id="tbl_past_allocation">
                      <tr>
                        <td class="txt-right" style="font-size:11px;">Employee Name</td>
                        <td ><input placeholder=" John Doe" style="width:100px; border-radius:10px;" type="text" name="peename" id="peename" /></td>
                      </tr>
                      <tr>
                        <td class="txt-right" style="font-size:11px;">Home Department</td>
                        <td>          <select style="width:140px; border-radius:10px;" name="phomedept">

                <option value="select">Select Department</option></center>
                <option value="ADC/NFC Shipping Department">ADC/NFC Shipping Department</option>
                <option value="Administration">Administration</option>
                <option value="Receiving Department">Receiving Department</option>
                <option value="Cable">Cable Department</option>
                <option value="Department">CPM Department</option>
                <option value="Dispatch Clerk">Dispatch Clerk</option>
                </select></td>
                      </tr>

                      <tr>
                        <td class="txt-right" style="font-size:11px;">Sent to Department</td>
                        <td>          <select style="width:140px; border-radius:10px;" name="psentdept">

                <option value="select">Select Department</option></center>
                <option value="ADC/NFC Shipping Department">ADC/NFC Shipping Department</option>
                <option value="Administration">Administration</option>
                <option value="BP Receiving Department">BP Receiving Department</option>
                <option value="Cable Department">Cable Department</option>
                <option value="CPM Department">CPM Department</option>
                <option value="Dispatch Clerk">Dispatch Clerk</option>
                <option value="Inventory Control Department">Inventory Control Department</option>
                <option value="IRM Shipping Department">IRM Shipping Department</option>
                <option value="Kitting Department">Kitting Department</option>
                <option value="Lead">Lead</option>
                <option value="LSC Receiving Department">LSC Receiving Department</option>
                <option value="LSC Shipping Department">LSC Shipping Department</option>
                <option value="NAR E&O Department">NAR E & O Department</option>
                <option value="Non-Conformance Department">Non-Conformance Department</option>
                <option value="Performance Department">Performance Department</option>
                <option value="Quality Auditors">Quality Auditors</option>
                <option value="Quality Department">Quality Department</option>
                <option value="Returns Department">Returns Department</option>
                <option value="Software Department">Software Department</option>
                <option value="Special Ops Team">Special Ops Team</option>
                <option value="Supervisors">Supervisors</option>
                <option value="Training/Meetings/Projects">Training/Meetings/Projects</option>

                </select></td>
                      </tr>

                       <tr>
                        <td class="txt-right" style="font-size:11px;">Time Sent</td>
                    <td ><input placeholder=" mm-dd-yy hh:mm:ss" style="width:140px; border-radius:10px;" type="text" name="ptimesent" id="ptimesent" /></td>
                      </tr>

                      <tr>
                        <td class="txt-right" style="font-size:11px;">Time Returned</td>
             <td ><input placeholder=" mm-dd-yy hh:mm:ss" style="width:140px; border-radius:10px;" type="text" name="ptimereturned" id="ptimereturn" /></td>
                      </tr>


                    </table>
                    <!--tbl_equipment_details closed-->
                            <div>
         <input class="button" value="Submit Record" name="pastadd" type="submit" style="width:300px; cursor:pointer; margin-top:5px;">
                            </div>  
                            </form>

我在这方面遇到了一些不同的问题。

  1. 首先,我很好奇哪种格式最适合存储这种类型的时间。

  2. 用户在表单中输入此信息最容易的是什么?4个单独的输入然后将它们连接在一起?或 2 只要求他们以指定的格式输入?

4

1 回答 1

0

我认为单独的输入是最用户友好且最不容易出错的,因为它们都是选择框。然后将这些值连接在一起,就我个人而言,将它们转换为时间戳。时间戳也是 24/7 兼容的。:)

我总是使用 unix 时间戳来保存我的 GMT 日期。然后比较它们是简单的数学。

<?php

//
// Some comparison stuff
//

// 1 day = 86400 seconds
// mktime returns a unix timestamp.
$date1 = mktime(0, 0, 0, 1, 1, 2013); // Jan. 1st, 2013
$date2 = mktime(0, 0, 0, 1, 15, 2013); // Jan. 15th, 2013

// Get the difference
$diff = ($date2 / 86400) - ($date1 / 86400); // 14

echo $diff;

//
// Some conversion stuff
//
// Use mktime([$hour, $min, $sec, $mon, $day, $year]) if you have 
// a specific date you want converted into a timestamp, else use 
// time(), which is the current timestamp.
//
// Convert to human readable format
// 
$datetime = date("H:i:sa - M jS, Y", $timestamp); // $timestamp optional

echo $datetime; // e.g. 4:23:46pm - Jan 1st, 2013

?>

PS 不要将我对“unix”时间戳的使用与 mysql 数据类型 TIMESTAMP 混淆。unix 时间戳是自 1970 年 1 月 1 日以来经过的秒数(作为整数)(?我相信?)。

// MySQL TIMESTAMP 数据类型。

The TIMESTAMP data type is used for values that contain both date and time parts.   
TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

如果我做了任何不正确的假设,请不要犹豫纠正我。谢谢!

于 2013-04-12T01:16:18.273 回答