Date Time To File Time - CSharp System.IO

CSharp examples for System.IO:File Time

Description

Date Time To File Time

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining a
using System.Text;
using System.IO;//  ww  w  .ja  v a 2s . c  o m
using System;

public class Main{
        private static void DateTimeToFileTime(DateTime value, out ushort date, out ushort time, out byte tenths)
        {
            if (value.Year < 1980)
            {
                value = FatFileSystem.Epoch;
            }

            date = (ushort)((((value.Year - 1980) << 9) & 0xFE00) | ((value.Month << 5) & 0x01E0) | (value.Day & 0x001F));
            time = (ushort)(((value.Hour << 11) & 0xF800) | ((value.Minute << 5) & 0x07E0) | ((value.Second / 2) & 0x001F));
            tenths = (byte)(((value.Second % 2) * 100) + (value.Millisecond / 10));
        }
        private static void DateTimeToFileTime(DateTime value, out ushort date, out ushort time)
        {
            byte tenths;
            DateTimeToFileTime(value, out date, out time, out tenths);
        }
        private static void DateTimeToFileTime(DateTime value, out ushort date)
        {
            byte tenths;
            ushort time;
            DateTimeToFileTime(value, out date, out time, out tenths);
        }
}

Related Tutorials