Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $hour = date("H") & ~3;
- $base = strtotime("$hour:00:00");
- $list = array();
- for($h=0; $h<24; ) {
- do {
- $time = strtotime("-$h hours", $base);
- $h += 4;
- } while(date("H", $time) == 4);
- $list[] = $time;
- }
- foreach($list as $time)
- printf(date("Y-m-d H:in", $time));
- 2016-02-06 16:00:00
- 2016-02-06 12:00:00
- 2016-02-06 08:00:00
- 2016-02-06 00:00:00
- 2016-02-05 20:00:00
- var list = [];
- var date = new Date();
- date.setHours(date.getHours() & ~3);
- date.setMinutes(0);
- date.setSeconds(0);
- for(var h=0; h<6; h++) {
- if(date.getHours() !== 4)
- list.push(Math.floor(date.getTime()/1000));
- date.setHours(date.getHours() - 4);
- }
- console.log(list);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement