dates的一些用法

1.創(chuàng)建CFDate對(duì)象:
CFAbsoluteTime absTime;
CFDateRef aCFDate;
absTime = CFAbsoluteTimeGetCurrent();
aCFDate = CFDateCreate(kCFAllocatorDefault, absTime);

2.對(duì)比兩個(gè)CFData對(duì)象
// Standard Core Foundation comparison result.
CFComparisonResult result;

// Create two CFDates from absolute time.
date1 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent());
date2 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent());

// Pass NULL for the context param.
result = CFDateCompare(date1, date2, NULL);
switch (result) {
case kCFCompareLessThan:
printf("date1 is before date2!\n");
break;
case kCFCompareEqualTo:
printf("date1 is the same as date2!\n");
break;
case kCFCompareGreaterThan:
printf("date1 is after date2!\n");
break;
}

3.驗(yàn)證公歷時(shí)間和把公歷時(shí)間轉(zhuǎn)為絕對(duì)時(shí)間CFAbsoluteTime
Boolean status;
CFGregorianDate gregDate;
CFAbsoluteTime absTime;

// Construct a Gregorian date.
gregDate.year = 1999;
gregDate.month = 11;
gregDate.day = 23;
gregDate.hour = 17;
gregDate.minute = 33;
gregDate.second = 22.7;

// Check the validity of the date.
status = CFGregorianDateIsValid(gregDate, kCFGregorianAllUnits);
printf("Is my Gregorian date valid? %d\n", status);

// Convert the Gregorian date to absolute time.
absTime = CFGregorianDateGetAbsoluteTime(gregDate, NULL);
printf("The Absolute Time from a Gregorian date is: %d\n", absTime);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容