2017-03-16 8 views
1

어떻게 할 수 있습니까? DAAppearance디스크 중재 시간이 인 유효한 타임 스탬프로 변환 되나요? DAAppearanceTime을 날짜로 변환

나는 다음과 같은 시도 :

511348742.912949

1986년 3월 16일 09 :

if let appearanceTime = diskinfo["DAAppearanceTime"] as? NSNumber{ 
          print(appearanceTime) 
          let date = NSDate(timeIntervalSince1970: TimeInterval(appearanceTime)) 
          print(date)        
         } 

내가 함수에서 다시 올바른 DAAppearanceTime를 얻을 수 있지만를 잘못 년도 변환 후 : 19 : 02 +0000

+0

타임 스탬프 '511348742.912949'에 대한 올바른 날짜를 얻었습니다. http://www.onlineconversion.com/unix_time.htm –

+0

즉, DiskArbitration이 잘못된 숫자를 제공하고 있다는 의미입니까? 시간은 정확하지만 내 USB 스틱은 1986 년 이래 연결되어 있지 않습니다. – nja

답변

1

"DAAppearanceTime" 키는 공식적으로 문서화되어 있지 않지만 DiskArbitration 프레임 워크는 오픈 소스입니다.

/* 
* Create the disk description -- appearance time. 
*/ 

time = CFAbsoluteTimeGetCurrent(); 

object = CFNumberCreate(allocator, kCFNumberDoubleType, &time); 
if (object == NULL) goto DADiskCreateFromIOMediaErr; 

CFDictionarySetValue(disk->_description, kDADiskDescriptionAppearanceTimeKey, object); 
CFRelease(object); 

DAInternal.c:

const CFStringRef kDADiskDescriptionAppearanceTimeKey = CFSTR("DAAppearanceTime" ); 

DADisk.c: 그래서 그 키의 값은 무엇 CFAbsoluteTimeGetCurrent() 반환하고, 그것은

절대 시간이 상대적 초 단위로 측정된다 Jan 1 2001 00:00:00 GMT의 절대 참조 날짜.

는이 같은 Date로 변환 :

if let time = diskinfo["DAAppearanceTime"] as? Double { 
    let date = Date(timeIntervalSinceReferenceDate: time) 
    print(date) 
} 

이이 날짜 2017-03-16 09:19:02 +0000 결과 값 511348742.912949하십시오.