What is the precision of *.datenum, which dir() returns

조회 수: 1 (최근 30일)
Mads
Mads 2018년 5월 7일
댓글: Jan 2018년 5월 8일
When I apply dir() to a file I get a struct with folder, name, date, bytes, and also datenum. How many significant digits do I need to fully store the number correctly, e.g., when I need to compare two files...
Say I print the number to an ascii file: fprintf(fid,'%.xf',mystruct.datenum) what is x supposed to be?

답변 (2개)

dpb
dpb 2018년 5월 7일
datenum is a double; hence has 15-16 significant digits; the safest way to store it is as a double but you'll get as close as can with '%.16g'
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 5월 7일
Since it is a double, use num2hex() to convert it to hex.

댓글을 달려면 로그인하십시오.


Jan
Jan 2018년 5월 7일
편집: Jan 2018년 5월 7일
The precision of the date depends on the file system. Linux' ext4 file system supports nanoseconds, NTFS uses 100 nanoseconds, FAT has a resolution of 2 seconds.
Under Windows FEX: GetFileTime can reply the native UINT64 file times:
T = GetFileTime(FileName, 'native')
T.Write
>> 131499596832223845
Using this integer avoids rounding and precision problems of the doubles used for Matlab's datenum format.
  댓글 수: 2
Mads
Mads 2018년 5월 8일
Interesting discussion. What if a jpeg was captured on a Nikon or smartphone, and stored on a Linux system or mac? Do datenums get rounded when transfered?
Is there a getfiletime for matlab running on mac?
Jan
Jan 2018년 5월 8일
There are two possibilities: Either moving the file keeps the dates, that the time is rounded to the precision of the file system. Or the function to move the file (e.g. the operating system) uses the current date as date of creation.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by