Converts local DateTime to local FILETIME, or UTC DateTime to UTC FILETIME. - CSharp System

CSharp examples for System:DateTime UTC

Description

Converts local DateTime to local FILETIME, or UTC DateTime to UTC FILETIME.

Demo Code

// Copyright (c) .NET Foundation. All rights reserved.
using System.Windows.Forms;
using OpenLiveWriter.Interop.Windows;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Diagnostics;
using System;/*from w  w w . j a  v a2 s.  com*/

public class Main{
        /// <summary>
        /// Converts local DateTime to local FILETIME,
        /// or UTC DateTime to UTC FILETIME.
        /// </summary>
        public static System.Runtime.InteropServices.ComTypes.FILETIME ToFileTime(DateTime dateTime)
        {
            long fileTimeVal = dateTime.Ticks - BASETICKS;
            System.Runtime.InteropServices.ComTypes.FILETIME result = new System.Runtime.InteropServices.ComTypes.FILETIME();
            result.dwHighDateTime = (int)(fileTimeVal >> 32);
            result.dwLowDateTime = (int)(fileTimeVal & 0xFFFFFFFF);
            return result;
        }
}

Related Tutorials