file time to dos time

Gordon McMillan gmcm at hypernet.com
Wed Dec 22 11:39:23 EST 1999


Nick Collier writes:
> 
> I'm trying to convert the results of os.path.getmtime(path) -
> last modification time in seconds since the epoch - to the dos
> time format which I think is a 36 bit number with bit fields for
> the year, month, day, hour, seconds. I'm coming close with some
> guessed at bitwise arthimetic, but can't get the year correct.
> Any suggestions?

Since what you're doing is platform specific, why not use 
DosDateTimeToTime from the Win32 extensions?

MSVC Help text says (hope the paste comes out looking OK):
wFatDate 
Specifies the MS-DOS date. The date is a packed 16-bit value 
with the following format: 
{PRIVATE}Bits 
Contents 

0-4 
Day of the month (1-31) 

5-8 
Month (1 = January, 2 = February, and so on) 

9-15 
Year offset from 1980 (add 1980 to get actual year) 

wFatTime 
Specifies the MS-DOS time. The time is a packed 16-bit value with 
the following format: 
{PRIVATE}Bits 
Contents 

0-4 
Second divided by 2 

5-10 
Minute (0-59) 

11-15 
Hour (0-23 on a 24-hour clock) 




- Gordon




More information about the Python-list mailing list