本文介绍了如何将unix时间戳上下舍入最接近的半小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在我的CRM系统中处理一个日历应用程序,我需要找到半个小时的上限和下限,从而缩短了某人在日历中输入事件的时间戳,以便运行一些SQL DB确定他们是否已经在该时间段内预订了某些东西。

Ok so I am working on a calendar application within my CRM system and I need to find the upper and lower bounds of the half an hour surrorunding the timestamp at which somebody entered an event in the calendar in order to run some SQL on the DB to determine if they already have something booked in within that timeslot.

例如我的时间戳为1330518155 = 29二月2012 16:22:35 GMT + 4
所以我需要得到1330516800和1330518600等于16 00和16:30。

For example I have the timestamp of 1330518155 = 29 February 2012 16:22:35 GMT+4so I need to get 1330516800 and 1330518600 which equal 16:00 and 16:30.

如果任何人有任何想法或认为我正在以愚蠢的方式开发日历让我知道!我的第一次这样的任务涉及到如此多的工作与时间和日期,所以任何建议赞赏!

If anyone has any ideas or think I am approaching developing the calendar in a stupid way let me know! Its my first time on such a task involving so much work with times and dates so any advice appreciated!

推荐答案

使用模数。 / p>

Use modulo.

$prev = 1330518155 - (1330518155 % 1800);
$next = $prev + 1800;

模运算符给出了除法的剩余部分。

The modulo operator gives the remainder part of division.

这篇关于如何将unix时间戳上下舍入最接近的半小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 23:37