NSDate,iosnsdate

來源:互聯網
上載者:User

NSDate,iosnsdate

【NSDate】

【注】NSDate是時間類,可以建立一個時間點的對象。

【另】物件導向程式講究一切事物皆對象,無論是具象事物還是抽象事物。


+ (id)date;
返回系統時間

+ (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs; 

返回以目前時間為基準,然後過了secs秒的時間

+ (id)dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)

secs;

返回以2001/01/01 GMT為基準,然後過了secs秒的時間

+ (id)dateWithTimeIntervalSince1970:(NSTimeInterval)secs;

返回以1970/01/01 GMT為基準,然後過了secs秒的時間


- (NSTimeInterval)timeIntervalSinceNow;

以目前時間(Now)為基準時間,返回執行個體儲存的時間與目前時間(Now)的時 間間隔

- (NSTimeInterval)timeIntervalSince1970;

以1970/01/01 GMT為基準時間,返回執行個體儲存的時間與1970/01/01 GMT 的時間間隔

- (NSTimeInterval)timeIntervalSinceReferenceDate;

以2001/01/01 GMT為基準時間,返回執行個體儲存的時間與2001/01/01 GMT 的時間間隔



+ (id)distantFuture;

返回很多年以後的未來的某⼀一天。 比如你需要⼀一個比現在(Now)晚(大)很長時間的時間值,則可以調用該方法。

+ (id)distantPast;

返回很多年以前的某⼀一天。

比如你需要⼀一個比現在(Now)早(小)大很長時間的時間值,則可以調用該方法。


- (id)addTimeInterval:(NSTimeInterval)secs; 

返回以目前的執行個體中儲存的時間為基準,然後過了secs秒的時間






【NSTimeZone】

【注】時區類,用於時區轉換

+ (NSTimeZone *)systemTimeZone;

//返回當前系統時區

+ (NSDictionary *)abbreviationDictionary;

//返回TimeZone支援時區的鍵值對

+ (id)timeZoneWithAbbreviation:(NSString *)abbreviation;

//通過傳入鍵值對的鍵,建立對應的時區對象。



【NSDateFormatter】

【注】時間戳記,用於顯示時間

//建立時間戳記

NSDateFormatter * dateFormatter = [[NSDateFormatteralloc] init];


//使用時間戳的目的,是為了自訂時間的列印格式

dateFormatter.dateFormat =@"yyyy年MM月dd日 HH:mm:ss.S";

        

//後設定會頂替原設定

dateFormatter.dateFormat =@"yy-MM-dd ahh時mm分ss秒";


//設定時區,如果不設,預設是系統時區

dateFormatter.timeZone = [NSTimeZonetimeZoneWithAbbreviation:@"CST"];


//根據風格,返回時間列印的字串

NSLog(@"%@", [dateFormatterstringFromDate:date]);



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.