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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题