文件集创建时间问题 [英] File setCreation time problem

查看:68
本文介绍了文件集创建时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试重设文件(或相关目录)的创建日期时,下面的代码实际上都会从文件中清除创建日期.我只是不明白.
有人可以指出我的错误吗?

When ever I try to reset the creation date of a file (or directory for that matter), the code below actually wipes out the creation date from the file. I'm just not getting it.
Can anyone please point out my mistake?

目前我有:

Currently I have:

字符串AdjustedDate = tmpMonthDate +-" + tmpDayDate +-" + tmpYear +" 11:00 AM;
string AdjustedDate = tmpMonthDate + "-" + tmpDayDate + "-" + tmpYear + " 11:00 AM";

推荐答案

我的猜测是日期或月份少于10,这意味着您只会得到一位数字在AdjustedDate的该字段中,这意味着ParseExact将失败,因为格式必须完全匹配.你需要强迫一个月日 到两位数(年份也可以到四位数,尽管现在已经可以了).

My guess is that either the day or the month is less than 10, which means that you will only get one digit in that field of AdjustedDate, which means that ParseExact will fail because the format must be an exact match. You need to force the month and day to two digits (and the year to four digits, although it's probably okay already).

         //string AdjustedDate = tmpMonthDate + "-" + tmpDayDate + "-" + tmpYear + " 11:00 AM";
         string AdjustedDate = string.Format("{0:00}-{1:00}-{2:0000} 11:00 AM", tmpMonthDate, tmpDayDate, tmpYear);


这篇关于文件集创建时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆