使用 NSDate,NSCalendar, NSDateComponents 獲得時間之差總結
2009-09-27 JHorn
方法一
NSDate* toDate1 = [ [ NSDate alloc] initWithString:@"2520-9-26 17:10:00 +0600" ];
NSTimeInterval distance = [ toDate1 timeIntervalSinceNow ];
NSTimeInterval iDat = distance / ( 86400 ) ;
NSLog( @" From now to %@ diff: %f ", [toDate1 description ], iDat );
[ toDate1 release ];
NSDate* toDate = [ [ NSDate alloc] initWithString:@"2009-9-29 0:0:00 +0600" ];
NSDate* startDate = [ [ NSDate alloc] init ];
NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];
NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit | NSDayCalendarUnit
| NSMonthCalendarUnit | NSYearCalendarUnit;
NSDateComponents *cps = [ chineseClendar components:unitFlags fromDate:startDate toDate:toDate options:0];
NSInteger diffHour = [ cps hour ];
NSInteger diffMin = [ cps minute ];
NSInteger diffSec = [ cps second ];
NSInteger diffDay = [ cps day ];
NSInteger diffMon = [ cps month ];
NSInteger diffYear = [ cps year ];
NSLog( @" From Now to %@, diff: Years: %d Months: %d, Days; %d, Hours: %d, Mins:%d, sec:%d",
[toDate description], diffYear, diffMon, diffDay, diffHour, diffMin,diffSec );
[ toDate release ];
[ startDate release ];
[ chineseClendar release ];
相關文章
- 直播平臺原始碼,iOS中使用 Date/NSDate 來獲取時間原始碼iOS
- NSDate 時間比較中的時區問題.
- MySQL 獲得當前日期時間(以及時間的轉換)MySql
- 由system.currentTimeMillis() 獲得當前的時間
- 使用Python獲取DNS解析時間和響應時間PythonDNS
- Linux時間的獲取與使用Linux
- MySQL如何獲取binlog的開始時間和結束時間MySql
- 細說PHP筆記08(第12章)--日期和時間,建立時間戳,mktime轉換unix時間戳,獲取字串時間,獲得日期和時間資訊,日期和時間格式化輸出,microtime()獲取微秒數PHP筆記時間戳字串
- MySQL如何快速獲取binlog的開始時間和結束時間MySql
- PHP獲取當前季度的開始時間和結束時間PHP
- oracle的interval時間格式的總結Oracle
- Python時間模組常用操作總結Python
- yapi 如何獲得: 當前時間和 n 天后的時間作為引數進行請求API
- 倒數計時快取時間問題總結快取
- 如何使用cURL獲得請求/響應具體耗時?
- Python中的時間處理大總結Python
- php 獲取今日、昨日、上週、本月的起始時間戳和結束時間PHP時間戳
- java 定時任務 quartz 時間表示式Cron總結Javaquartz
- PHP獲取當月起始和結束時間戳PHP時間戳
- 獲取時間戳,幾個時間點的時間戳時間戳
- linux獲取最新檔案時間以及sshpass使用Linux
- C++日期和時間程式設計總結C++程式設計
- 使用 Element+vue實現開始時間結束時間限制Vue
- c++ 獲取當前時間周初凌晨時間戳(獲取當前時間週一凌晨時間戳)C++時間戳
- 使用VUE寫一段時間專案的個人總結-元件篇Vue元件
- Python之時間和日期使用小結Python
- Java 獲取本地時間與網路時間Java
- 2023年終總結:為何我們總想把時間填滿
- 獲取系統時間
- php 獲取時間差PHP
- 獲取當前時間
- 總結:使用MyBatis Generator時遇到的坑MyBatis
- 從部落格時間軸總結這一年
- 專案總結 | 對【時間】構建的特徵工程特徵工程
- 001量化專案總結 --01獲取實時價格
- SpringBoot獲得Maven-pom中版本號和編譯時間戳詳細步驟Spring BootMaven編譯時間戳
- mybatis獲取當前時間MyBatis
- QT獲取日期,時間,星期QT
- C++11獲取時間C++