ms项目中的Task.Duration属性
我必须如何转换 Task.Duration
才能获得有效结果? 我在 MSDN 中找到了有关此属性的说明:
获取或设置任务的持续时间(以分钟为单位)。
但它不能正确工作。
如果我将结果除以 60(小时中的分钟)和 24(一天中的小时),我会得到错误的结果。
但如果我除以 20 和 24 就可以了。我不明白为什么。 我在 .Net 3.5 和 Office 主互操作程序集(Office 2010 的 Microsoft.Office.Interop.MSProject
)上使用 C#。
我使用该代码:
void SetProperties(MSProject.Task o, string version)
{
Wbs = o.WBS.ToString();
Name = o.Name.ToString();
StartDate = (System.DateTime) o.Start;
FinishDate = (System.DateTime)o.Finish;
Iteration = version;
duration = (Convert.ToInt16(o.Duration)/10/24).ToString();//after result //divided by 2 I get correct result. Why?
}
谢谢
How I have to convert Task.Duration
that get valid result?
I find explanations about this property in MSDN:
Gets or sets the duration (in minutes) of a task.
But it doesn't work correct.
If I divided result by 60 (minutes in hour) and 24(hours in day) I get incorrect result.
But if I divided by 20 and 24 all it's ok. And I don't understand why.
I use C# on .Net 3.5 and Office Primary Interop Assemblies ( Microsoft.Office.Interop.MSProject
for office 2010).
I use that code :
void SetProperties(MSProject.Task o, string version)
{
Wbs = o.WBS.ToString();
Name = o.Name.ToString();
StartDate = (System.DateTime) o.Start;
FinishDate = (System.DateTime)o.Finish;
Iteration = version;
duration = (Convert.ToInt16(o.Duration)/10/24).ToString();//after result //divided by 2 I get correct result. Why?
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不能按您期望的方式工作的原因是因为一天中您没有 24 小时的工作时间。任务的持续时间是从开始到结束之间的工作时间,而不是绝对小时数。
由于一天的默认工作小时数为 8,因此您可以将总分钟数除以 480(60 分钟 * 8 小时)以获得天数。您计算出的 20 * 24 恰好也等于 480,因此您偶然发现了正确的数字。
当然,不要期望开始 + 持续时间(以天为单位)将等于您的完成日期。这是因为您还必须考虑非工作日,例如周末。因此,您可以有一个从周五开始的为期 3 天的任务,直到周二(5 个日历日)结束才能完成。
The reason that it doesn't work like you expect is because in a day you do not have 24 hours of working time. The Duration of a task is the amount of working time between the start and finish, not the absolute number of hours.
Since the default number of working hours in a day is 8, you divide the total minutes by 480 (60 min * 8 hours) to get the number of days. Your calculation of 20 * 24 just so happens to also equal 480, so you stumbled upon the correct number.
Of course, do not expect that Start + Duration (in days) is going to equal your Finish date. That's because you also have to factor in non-working days, like weekends. So you can have a 3 day task that starts on Friday, and it will not finish until the end of the day on Tuesday (5 calendar days).