ms项目中的Task.Duration属性

发布于 2025-01-06 15:06:07 字数 893 浏览 2 评论 0原文

我必须如何转换 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟稳重的好男人 2025-01-13 15:06:07

它不能按您期望的方式工作的原因是因为一天中您没有 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文