[英]Emit only unique values - or if a certain period of time has passed since last emit
[英]How to calculate the time that has passed since a file was created
我想計算自文件創建以來的時間,例如,如果文件是12個月前創建的,我想將其刪除。 我現在有這個:
DateTime fileCreatedDate = File.GetCreationTime(path);
謝謝!
從DateTime.Now減去fileCreatedDate-應該可以工作:
DateTime fileCreatedDate = File.GetCreationTime(path);
var timespan = DateTime.Now - fileCreatedDate;
if(timespan.Days > 365)
{
File.Delete(path);
}
嘗試這個
DateTime fileCreatedDate = File.GetCreationTime(path);
TimeSpan difference = DateTime.Now.Subtract(fileCreatedDate);
if(difference.TotalDays > 365)
{
}
希望這可以幫助
你可以這樣做
DateTime fileCreatedDate = File.GetCreationTime(path);
if((DateTime.Now - fileCreatedDate ).Days > 365)
{
File.Delete(path);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.