I was told to use the MPXJ to generate a project file with task that spans no more than several hours, or even minutes only. Everything seems to work when the duration of a task is specified in days, or if the task doesn't have resources assigned. But if the task has resources assigned and has to start or finish at a specified time (for example, at 14:35), despite I'm specifying the time in the code, when I load the generated file in MS Project, time is ignored. We can show the effect using this file included with MPXJ source code. Let's change the start date of the task3
to include time:
//
// Create the second sub task
//
Task task3 = task1.addTask();
task3.setName("Second Sub Task");
task3.setStart(df.parse("11/01/2003 14:00"));
task3.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
But when I load the generated file using MS Project, this is what happens:
How can I specify the start and end time of a task so MS Project respects it?
I think the date format you are working with in the sample code is not set up to parse the time component of the string you are passing:
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
You probably need something like this:
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");