1.原數據格式
2016-11-10 18:17:23
2.需求
- 與特定時間進行比較,完成判斷邏輯
3.思路
1.將原數據格式轉變?yōu)閕nt或string,便于邏輯運算;
2.將輸入數據控制為int或string,便于邏輯運算;
3.使用int經行比值判斷,string進行等值判斷;
4.demo
// 將系統時間戳轉為string 20161110
$s_createdTime = str_replace("-", "", substr($o_consume->createdTime, 0, 8));
// 獲取輸入時間,注意控制類型
$s_date = $this->input->expectType('p:date', 'string', '');
// 比值運算
if ($s_createdTime == $s_date) {
// do something
}
5.詳細分析
打印系統格式時間戳createdTime發(fā)現其類型為string,因此可以使用substr()截取系統格式字符串前n位;
由于系統格式的時間戳格式為2016-11-10,為便于比值及運算,去除短橫線以控制其格式str_replace();
string類型無法進行>或<的比值計算,所以如有需要可以將其轉換為int類型floatval();