Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active December 17, 2015 04:59
Show Gist options
  • Save prashantvc/5554830 to your computer and use it in GitHub Desktop.
Save prashantvc/5554830 to your computer and use it in GitHub Desktop.
Sets the last modified date time to file
private static readonly DateTime Jan1st1970 = new DateTime
(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long CurrentTimeMillis()
{
return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
}
public static DateTime GetDateFromMilliSeconds(long milliseconds)
{
return Jan1st1970.AddMilliseconds(milliseconds);
}
static void WriteLastAccessedTime ()
{
string documentsPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
string path = System.IO.Path.Combine (documentsPath, "text.txt");
File file = new File (path);
if (!file.Exists ()) {
file.CreateNewFile ();
}
try {
using (var buffer = new BufferedWriter (new FileWriter (file, true))) {
buffer.Append ("Hello");
buffer.Close ();
}
System.Console.WriteLine (file.LastModified ());
var time = CurrentTimeMillis ();
file.SetLastModified (time);
System.Console.WriteLine (GetDateFromMilliSeconds(file.LastModified()));
}
catch (System.Exception ex) {
System.Console.WriteLine (ex.ToString ());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment