異なるユニットのタスク時間を計算します
数分、時間など、さまざまなユニットでタスクの持続時間を計算すると便利です。
時間の計算 タスククラスの提供は、異なるユニットでタスク期間を計算するためのgetDuration()メソッドを提供します。この方法では、タイムナイタイプが入力引数として取り上げられ、持続時間を2倍の値として返します。
次のコードは、この方法を使用して、瞬間、日、時間、毎月、さまざまなユニットでタスクの持続時間を取得する方法を示しています。
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(TaskDurationInDifferentUnits.class);
4
5// Read MS Project template file
6String fileName = dataDir + "SampleProject.mpp";
7
8// Read the input file as Project
9Project project = new Project(fileName);
10
11// Get a task to calculate its duration in different formats
12Task task = project.getRootTask().getChildren().getById(1);
13
14// Get the duration in Minutes
15double mins = task.get(Tsk.DURATION).convert(TimeUnitType.Minute).toDouble();
16// Get the duration in Days
17double days = task.get(Tsk.DURATION).convert(TimeUnitType.Day).toDouble();
18// Get the duration in Hours
19double hours = task.get(Tsk.DURATION).convert(TimeUnitType.Hour).toDouble();
20// Get the duration in Weeks
21double weeks = task.get(Tsk.DURATION).convert(TimeUnitType.Week).toDouble();
22// Get the duration in Months
23double months = task.get(Tsk.DURATION).convert(TimeUnitType.Month).toDouble();