Ifelse Unix时间戳

时间:2018-11-14 19:00:14

标签: php

好,这是我的问题,我尝试使用三元运算符,并且在我的问题上使用开关中断,仍然得出相同的结果。

现在Iam尝试尝试ifelse是否可行,但是Iam仍然出现相同的错误,应该在该错误中回显“是P4”,但它指出 这是一个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 个答案:

答案 0 :(得分:0)

我感觉有点像了解和做家庭作业;-),但是我认为这是一个可行的解决方案...

$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 :(得分:0)

OrderNumber