C# Directory GetLastWriteTimeUtc

Description

Directory GetLastWriteTimeUtc Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last written to.

Syntax

Directory.GetLastWriteTimeUtc has the following syntax.


public static DateTime GetLastWriteTimeUtc(
  string path
)

Parameters

Directory.GetLastWriteTimeUtc has the following parameters.

  • path - The file or directory for which to obtain modification date and time information.

Returns

Directory.GetLastWriteTimeUtc method returns A structure that is set to the date and time the specified file or directory was last written to. This value is expressed in UTC time.

Example

The following example illustrates the differences in output when using Coordinated Universal Time (UTC) output.


using System;/* w  w w .j  a va 2s .  co  m*/
using System.IO;

public class DirectoryUTCTime
{
  public static void Main()
  {
     string n = @"C:\test\newdir";
     DateTime dtime1 = new DateTime(2014, 1, 3);
     DateTime dtime2 = new DateTime(1999, 1, 1);
    
     Directory.SetCreationTime(n, dtime1);
     Directory.SetLastAccessTimeUtc(n, dtime1);
    
     Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n));
     Console.WriteLine("UTC creation Date: {0}", Directory.GetCreationTimeUtc(n));
     Console.WriteLine("Last write time: {0}", Directory.GetLastWriteTime(n));
     Console.WriteLine("UTC last write time: {0}", Directory.GetLastWriteTimeUtc(n));
     Console.WriteLine("Last access time: {0}", Directory.GetLastAccessTime(n));
     Console.WriteLine("UTC last access time: {0}", Directory.GetLastAccessTimeUtc(n));
    
     Directory.SetLastWriteTimeUtc(n, dtime2);
     Console.WriteLine("Changed last write time: {0}", Directory.GetLastWriteTimeUtc(n));
  }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter