1.创建CFDate对象:
CFAbsoluteTime absTime;
CFDateRef aCFDate;
absTime = CFAbsoluteTimeGetCurrent();
aCFDate = CFDateCreate(kCFAllocatorDefault, absTime);
2.对比两个CFData对象
// 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.验证公历时间和把公历时间转为绝对时间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);