首页 > 解决方案 > UNIX时间,响应总是一分钟(更快/更少)PHP MySQL

问题描述

我们有一个考勤门户,其中员工应用程序需要显示倒计时到他们的班次开始(例如:员工班次是 9-5,当他们在 8:50 打开他们的应用程序时,服务器将给出响应10 分钟,应用程序将开始倒计时 {9:59, 9:58....etc})

我们将所有时间存储在 UTC 中,并使用 PHP 函数转换为本地时间。

这一切都很好,直到上周我们开始注意到响应总是延迟一分钟(因此对于上面的示例,将显示剩余 9:00 分钟等)。无论轮班的时间或轮班开始时间的差异。

以下是服务器端逻辑:

$fields['total_elapsed_time'] = $current_time - strtotime($first_check_in_timestamp);
$fields['current_time'] = $current_time;

以下是应用程序逻辑:

```if currentTime < startTime {

                            self.isUserHaveShiftIn2Hours = true
                            let endDate = Date(timeIntervalSince1970: TimeInterval(startTime))
                            self.totalWorkingSeconds = Double(self.getNumberOfSeconds(startDate: startDate, endDate: endDate))
                            self.startTheCountDownForShift()

                        }```

`let startTime = response.result.value!.shift_start_time`
`let startDate = Date(timeIntervalSince1970: TimeInterval(currentTime))`
`let currentTime = response.result.value!.current_time`

谢谢!~

标签: phpmysqlunix-timestamp

解决方案


推荐阅读