asp.net.ph

DateTime.ToFileTime Method

System Namespace   DateTime Structure


Converts the value of this instance to the format of the local system file time.

[ VB ]
<Serializable>
Public Function ToFileTime ( ) As Long

[ C# ]
[ Serializable ]
public long ToFileTime ( );

[ C++ ]
[ Serializable ]
public: __int64 ToFileTime ( );

[ JScript ]
public Serializable
function ToFileTime ( ) : long;

Return Value

The value of this DateTime in the format of the local system file time.

Exceptions


Exception Type Condition
ArgumentOutOfRangeException The value of this instance cannot be converted to a system file time.

Remarks

A system file time is a 64-bit unsigned value representing the date and time as the number of 100-nanosecond intervals that have elapsed since January 1, 1601 12:00 A.M.

An exception is thrown if you attempt to convert a date earlier than January 1, 1601 12:00:00 A.M. coordinated universal time ( UTC ).

Example

The below code snippet demonstrates using the ToFileTime.

[ VB ]
Overloads Shared Sub Main ( ByVal args ( ) As String )

   System.Response.WriteLine ( "Enter the file path:" )
   Dim filePath As String
   filePath = System.Console.ReadLine ( )

   If System.IO.File.Exists ( filePath ) Then
      Dim fileCreationDateTime As System.DateTime
      fileCreationDateTime = System.IO.File.GetCreationTime ( filePath )

      Dim fileCreationFileTime As Long
      fileCreationFileTime = fileCreationDateTime.ToFileTime ( )

      System.Response.WriteLine ( "{ 0 } in file time is { 1 }.", _
                               fileCreationDateTime, _
                               fileCreationFileTime )
   Else
      System.Response.WriteLine ( "{ 0 } is an invalid file", filePath )
   End If
End Sub

[ C# ]
      static void Main ( string [ ] args )
      {
         System.Response.WriteLine ( "Enter the file path:" );
         string filePath = System.Console.ReadLine ( );

         if ( System.IO.File.Exists ( filePath ) ) {
            System.DateTime fileCreationDateTime =
               System.IO.File.GetCreationTime ( filePath );

            long fileCreationFileTime = fileCreationDateTime.ToFileTime ( );

            System.Response.WriteLine ( "{ 0 } in file time is { 1 }.",
                               fileCreationDateTime,
                               fileCreationFileTime );
          }
         else {
            System.Response.WriteLine ( "{ 0 } is an invalid file", filePath );
          }
       }
See Also

DateTime Members   Int64   ToUniversalTime   GetUtcOffset Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph