如果条件显示年,月,日

时间:2016-01-28 15:55:33

标签: php if-statement

我是代码编写的外部,我有以下代码正在工作。

public static String gobble(InputStream in, String charsetName) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    in.transferTo(bos);
    return bos.toString(charsetName);
}

但我想再增加一个条件,但下面的代码无效。

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$difference = $datetime1->diff($datetime2);
echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>

我应该如何修改上述代码?

1 个答案:

答案 0 :(得分:0)

如果我没有错,你会忘记关闭else语句的大括号

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$datetime3 = new DateTime("$date_commenced_dormancy");
$datetime4 = date("Y-m-d");

if ($active_status ==('Live but Commenced Dormancy')) {
$difference = $datetime3->diff($datetime2);
} elseif  ($active_status ==('Dissolved')) {
$difference = $datetime1->diff($datetime2);
} else {
$difference = $datetime4->diff($datetime2);
}

echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>