使用 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
- php獲得時間PHP
- iOS時間那點事--NSDateiOS
- 把時間戳之差轉換成時分秒格式時間戳
- MySQL 獲得當前日期時間(以及時間的轉換)MySql
- Android ViewTreeObserver使用總結及獲得View高度的幾種方法AndroidViewServer
- js時間小總結JS
- 批處理獲得系統當前時間之前n天的時間
- 總結獲得【酷我音樂】歌曲URL地址
- 【C#學習筆記】獲得系統時間C#筆記
- NSDate使用筆記筆記
- 實現如何Android 獲得圖片的總結Android
- javascript如何獲得網頁最後被修改的時間JavaScript網頁
- ios 時間 string 和 nsdate問題 swift2 2 ociOSSwift
- 臨時表空間操作總結
- ORACLE臨時表空間總結Oracle
- SQL時間函式總結(二)SQL函式
- 漢得面試總結面試
- 使用Python獲取DNS解析時間和響應時間PythonDNS
- 細說PHP筆記08(第12章)--日期和時間,建立時間戳,mktime轉換unix時間戳,獲取字串時間,獲得日期和時間資訊,日期和時間格式化輸出,microtime()獲取微秒數PHP筆記時間戳字串
- PHP獲取當前季度的開始時間和結束時間PHP
- MySQL如何獲取binlog的開始時間和結束時間MySql
- Linux時間的獲取與使用Linux
- Python時間模組常用操作總結Python
- oracle的interval時間格式的總結Oracle
- 最近一段時間的總結
- Python時間格式歸納總結Python
- 關於時間格式化總結
- yapi 如何獲得: 當前時間和 n 天后的時間作為引數進行請求API
- 倒數計時快取時間問題總結快取
- 如何使用cURL獲得請求/響應具體耗時?
- php 獲取今日、昨日、上週、本月的起始時間戳和結束時間PHP時間戳
- java 定時任務 quartz 時間表示式Cron總結Javaquartz
- 使用VUE寫一段時間專案的個人總結-元件篇Vue元件
- 總結從“Thirst”模組所獲得的開發經驗和教訓
- PHP獲取當月起始和結束時間戳PHP時間戳
- Python時間獲取及轉換知識彙總Python
- c++ 獲取當前時間周初凌晨時間戳(獲取當前時間週一凌晨時間戳)C++時間戳