我正在制作自己的试用模式,我想知道是否有办法检查文本文件中的时间信息是否与Date.Today
?
private void Trial()
{
DateTime saveNow = DateTime.Today;
DateTime expiryDate = DateTime.Today.AddDays(30);
string fileName = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "trailexample.txt");
if (!File.Exists(fileName))
{
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
file.WriteLine(saveNow);
file.WriteLine(expireDate);
file.Close();
}
else if (File.Exists(fileName))
{
var lastLine = File.ReadLines(fileName).Last();
If (saveNow == LastLine) // This doesn't work of course but kinda the Idea. This is what I need help with.
{
messagebox.Show("Your trial is over");
}
}
}