Zend_Date 两个日期时间 mysql 值相减

发布于 2024-12-21 23:29:29 字数 258 浏览 6 评论 0原文

我正在构建一个小型应用程序来计算员工出勤率。

用户将签入,他的签入时间将以 mysql 日期时间格式记录,例如

check_in_time 2011-12-16 20:27:20

当他签出时,

check_out_time 2011-12-16 20:27:27

我可以通过爆炸和减法以传统方式完成,但我确信 Zend_Date 有更有效的方法做它。

i am building a small application to calculate employee attendance.

A user will check in, his check in time will be recorded in a mysql datetime format, for example

check_in_time 2011-12-16 20:27:20

And when he checks out

check_out_time 2011-12-16 20:27:27

I can do it the conventional way by exploding and doing the subtraction, but am sure Zend_Date has a more efficient way of doing it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2024-12-28 23:29:29

显然我的问题并不难回答,无论如何,这是获得以秒为单位的时间差异的答案,然后我可以正常处理秒。

感谢@ajreal 的文档,我没有正确地研究它们。

public function getTimeInSeconds($dateStart, $dateEnd) {
    $dateStart = new Zend_Date($dateStart);
    $dateEnd = new Zend_Date($dateEnd);
    $new = $dateStart->sub($dateEnd);
    $timeInSeconds = $new->getTimestamp();
    return $timeInSeconds;
}

Obviously my question was not hard to answer, anyhow this is the answer to get the time diff in seconds, then i can handle seconds normally.

Thanks for the docs @ajreal, i did not look correctly into them.

public function getTimeInSeconds($dateStart, $dateEnd) {
    $dateStart = new Zend_Date($dateStart);
    $dateEnd = new Zend_Date($dateEnd);
    $new = $dateStart->sub($dateEnd);
    $timeInSeconds = $new->getTimestamp();
    return $timeInSeconds;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文