[英]Perform Function on Specific Date
我正在嘗試在特定日期進行操作。 這是一個“例子”
如果是2017年6月5日, {
}其他{
}
顯然,粗體部分在Swift中不起作用。 這就是我要弄清楚的部分。 我將如何完成?
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day], from: date)
let year = components.year
let month = components.month
let day = components.day
if(month == 6 && day == 5 && year == 2017) { //June 5 2017
//Code
}else{
//Code
}
確保使用let來提高性能,因為您不需要更改這些變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.