dongqiuqiu4736 2018-11-14 19:00
浏览 10
已采纳

Ifelse unix时间戳

Ok here is my issue I tried to use a Ternary operator and a switch break on my issue and still coming up with the same results.

Now Iam trying an ifelse to see if this works but Iam still getting the same error where it should be echoing out "is a P4" but instead it's stating that this is a P1

<?php
//************************************
//https://stackoverflow.com/questions/53180920/unix-time-stamp-adding-  2-weeks-4-weeks-6-weeks-8-weeks/53181428#53181428
//unix time stamp 
//************************************
//1536079080 = 04-09-2018 (Day of the task)
//1541376000 = 11-06-2018 (todays date )
//1542758400 = 11-21-2018 (2 weeks and 1)
//************************************
// > Greater than
// < Less than 
// >=   Greater than or equal to
// <=   Less than or equal to
//************************************

$mod = 1536079080; //unix time stamp 
$moDate = new DateTime('@'. $mod, new   DateTimeZone('America/Los_Angeles')); //Unix change to PST time 
$today = date("d/m/Y"); //todays date


$twoWeeks = time() + (3600*24*14);  //NOW + ( 3600 sec = 1 hour * 24       hours/day * 14 days)
$fourWeeks= time() + (3600*24*28);
$sixWeeks = time() + (3600*24*42);
$eightWeeks = time() + (3600*24*56);


// Less than or equal to and less than
$p1 = ($mod <= $twoWeeks && $mod < $fourWeeks)? true : false;
$res1 = ($p1) ? 'Is a P1' : 'Is not a P1'."<br>";

//Greater than or equal to and less then  6 weeks
$p2 = ($mod >= $fourWeeks && $mod < $sixWeeks)? true : false;
$res2 = ($p2) ? 'is a P2' : 'Is not a P2'."<br>";

//Greater than or equal to and less then 8 weeks
$p3 = ($mod >= $sixWeeks && $mod < $eightWeeks)? true : false;
$res3 = ($p3) ? 'Is a P3' : 'Is not a P3'."<br>";

// is equal to 8 weeks and greater then 8 weeks
$p4 = ($mod == $eightWeeks && $mode > $eightWeeks)? true : false;
$res4 = ($p4) ? 'Is a P4' : 'Is not a P4'."<br>";




echo $res1 , $res2, $res3, $res4;

//Output
//Is a P1
//Is not a P2
//Is not a P3
//Is not a P4

?>
  • 写回答

2条回答 默认 最新

  • dongzhi2332 2018-11-14 19:27
    关注

    I feel a bit like understanding and doing your home work ;-) but here is a feasible solution, I think...

    $mod = 1546079080; //unix time stamp
    $moDate = new DateTime('@'. $mod, new   DateTimeZone('America/Los_Angeles')); 
    //Unix change to PST time
    $today = date("d/m/Y"); //todays date
    echo $mod . "<br>";
    
    $twoWeeks = time() + (3600*24*14);  //NOW + ( 3600 sec = 1 hour * 24       hours/day * 14 days)
    $fourWeeks= time() + (3600*24*28);
    $sixWeeks = time() + (3600*24*42);
    $eightWeeks = time() + (3600*24*56);
    
    
    // Period 1 between 2 and 4 weeks from now
    $p1 = ($mod == $twoWeeks && $mod < $fourWeeks)? true : false;
    $res1 = ($p1 ? 'Is a P1' : 'Is not a P1')."<br>";
    
    // Period 2 between 4 and 6 weeks from now
    $p2 = ($mod >= $fourWeeks && $mod < $sixWeeks)? true : false;
    $res2 = ($p2 ? 'is a P2' : 'Is not a P2')."<br>";
    
    // Period 3 between 6 and 8 weeks from now
    $p3 = ($mod >= $sixWeeks && $mod < $eightWeeks)? true : false;
    $res3 = ($p3 ? 'Is a P3' : 'Is not a P3')."<br>";
    
    // Period 4 more than 8 weeks in future
    $p4 = ($mod >= $eightWeeks) ? true : false;
    $res4 = ($p4 ? 'Is a P4' : 'Is not a P4')."<br>";
    
    echo $twoWeeks .'<br>'. $fourWeeks .'<br>'.  $sixWeeks .'<br>'. $eightWeeks .'<br><br>' ;
    echo $res1 , $res2, $res3, $res4;
    
    // Output
    // 1546079080
    // 1543432972
    // 1544642572
    // 1545852172
    // 1547061772
    // 
    // Is not a P1
    // Is not a P2
    // Is a P3
    // Is not a P4
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大