Berechnen Sie die Aufgabendauer in verschiedenen Einheiten

Es kann nützlich sein, die Dauer einer Aufgabe in verschiedenen Einheiten wie Minuten, Stunden usw. zu berechnen.

Berechnung von Dauern Die Aufgabe -Kläufe bietet die Methode getDuration () zur Berechnung der Aufgabendauer in verschiedenen Einheiten. Diese Methode nimmt Timeunittype als Eingabemargument an und gibt die Dauer als Doppelwert zurück.

Der folgende Code zeigt, wie Sie diese Methode verwenden, um die Dauer einer Aufgabe in verschiedenen Einheiten abzurufen: Minute, Tag, Stunde, Woche und Monat.

 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();
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.