比較指定日期是否在當前日期之前

2021-10-03 12:31:09 字數 506 閱讀 6847

開發中常常遇到對某個日期與當前日期進行比較,在對日期格式進行轉換時不注意容易忽視時區差異,日期轉換的時間是北京時間,而通過[nsdate date]獲取到的是格林尼治時間,存在8個小時的誤差存在

在時區的設定調整可以通過以下:[dateformatter settimezone:[nstimezone timezoneforsecondsfromgmt:8]];

//或者

dateformattersettimezone:[nstimezone timezonewithabbreviation:@「utc」]];

#pragma mark -- 比較指定日期是否在當前日期之前

- (bool)checkproductdate:(nsstring *)tempdate

if (y == ty && m > tm)

if (y == ty && m == tm && d >= td)

return yes;

}

當前日期與制定日期的比較

1 首先獲取當前日期nsdate形式,指定乙個日期格式 pragma mark 得到當前時間 nsdate getcurrenttime2 然後將指定日期 此處以2016 09 30 00點為例 轉換為同樣日期格式,返回nsdate形式 nsdateformatter dateformatter n...

根據當前日期 天數,取得當前日期減去天數之前的日期

根據當前日期 天數,取得當前日期減去天數之前的日期 方法一 dateformat sdformat new dateformat yyyy mm dd date newdate new date string enddate sdformat.format newdate 取得系統時間的當前日期,即...

linux 刪除指定日期之前的檔案

es沒有指定日誌時預設在var的log下面 用 edf cluster.log 這個來清空當前日誌檔案內容,且仍然保留檔名,只清空內容 兩種方法 1.在乙個目錄中保留最近三個月的檔案,三個月前的檔案自動刪除。find email v2 bak mtime 92 type f name mail 12...