File Time To Date Time - CSharp System.IO

CSharp examples for System.IO:File Time

Description

File Time To Date Time

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining a
using System.Text;
using System.IO;//from w  w w  .  j  a va 2  s  .co m
using System;

public class Main{
        private static DateTime FileTimeToDateTime(ushort date, ushort time, byte tenths)
        {
            if (date == 0 || date == 0xFFFF)
            {
                // Return Epoch - this is an invalid date
                return FatFileSystem.Epoch;
            }

            int year = 1980 + ((date & 0xFE00) >> 9);
            int month = (date & 0x01E0) >> 5;
            int day = date & 0x001F;
            int hour = (time & 0xF800) >> 11;
            int minute = (time & 0x07E0) >> 5;
            int second = ((time & 0x001F) * 2) + (tenths / 100);
            int millis = (tenths % 100) * 10;

            return new DateTime(year, month, day, hour, minute, second, millis);
        }
}

Related Tutorials