Swift 早安、午安、晚安

Date 當天小時的比較

下午接到老闆指示,問候語句要隨著時間調整。

下午的問候語顯示”早安”也似乎蠻奇怪的。

那當天的小時比較怎麼做? 我們設定判斷標準是 12:00 及 18:00。

取得現在時間使用 Date(),

只有同樣的種類才可以比較,我們這邊使用timeIntervalSince1970 換算,然後轉換成為Int做比較。

使用 常數ss 塞值,讓goodAfternoon及goodEvening 總是 在當天的12:00及18:00。

字串轉換成Date,才可以使用timeIntervalSince1970。

其他參考

目前網路上有比較天數差異https://blog.csdn.net/jhy835239104/article/details/80492241?utm_medium=distribute.pc_relevant.none-task-blog-title-3&spm=1001.2101.3001.4242

還有比較Date()格式,使用升冪降冪做比較

https://blog.csdn.net/wa172126691/article/details/80242224

--

--

Major in physical education. Football referee. And high interest in looking the world through the numbers.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.