Service Desk Practitioners Forum

Date in Web-api

Go to solution
Super Contributor.

Date in Web-api


I am trying to get all fields of a service call with a JAVA program using web-api. The problem is with Dates, in witch I cannot get the full date, only a number. For example, to get the Actual finish of a service call sc.getActualFinish().toString() give me the number 38734.708333333336.

How can I manage this kind of dates (to used them in actions like add days to a date or calculate mean time of service call resolution.)

Thanks a lot in advance.

Super Contributor.

Re: Date in Web-api

Hi also have the same problem with the duration of a WO. I can get the duration as a double variable but I want it as a hours and minutes register.

Any Idea.

Thanks Again,
Mauricio Consta
Honored Contributor.

Re: Date in Web-api

Hi Carlos, the next example adds one seccond to the actual finish of a service call and save it:

IServicecall sc = sc_hm.openServicecall(id);
double dateTimeFinish = sc.getActualFinish().doubleValue() ;
System.out.println("SC[" + id + "] ActualFinish to Null");
double second = 0.00000115740;
dateTimeFinish = dateTimeFinish + second;
System.out.println("SC[" + id + "] ActualFinish to " + ApiDateUtils.double2Date(new Double(dateTimeFinish)));

sc.setActualFinish(new Double(dateTimeFinish) );;

Note the use of the API function ApiDateUtils.double2Date, you can use that function to print dates in human readable form.

To add an interval to the date, you have to calculate the value in days, so in the example I'm adding a second, so I add:

seccond = 1 / (60*60*24)

60*60*24 = number of secconds in a day.

Hope this helps!
Super Contributor.

Re: Date in Web-api

Perfect but...
Where can I find the "ApiDateUtils"?

Thanks a lot. That's what I needed !!

Ganesha Sridhar
Outstanding Contributor.

Re: Date in Web-api

Hello Carlos,

The method double2Date and date2Double and member of class "com.hp.ifc.util.ApiDateUtils" which is available in web-api.jar

Ganesha Sridhara

Please see the code:
import java.util.Date;

import com.hp.ifc.util.ApiDateUtils;

* @author Ganesha Sridhara

public class DateUtil

public static void main(String[] args)
Date dt = new Date("August 3,2004");

String lt = "107175517500";
Long nlt = new Long(lt);
Date newt = new Date(nlt.longValue());
String st = newt.toLocaleString();

// Double to Date
// System.out.println("Usgin WEB-API Date2Dobule " + ApiDateUtils.date2Double(dt));
// System.out.println("Usgin WEB-API Date2Dobule " + ApiDateUtils.double2Date(ApiDateUtils.date2Double(dt)));

// ------------------------ Begin --------------------------
Double ftTime = new Double(2.2916667461395264);
Double ttTime = new Double(2.625);

System.out.println("From " + ApiDateUtils.double2Date(ftTime));
System.out.println("To " + ApiDateUtils.double2Date(ttTime));

// ------------------------ End --------------------------

Super Contributor.

Re: Date in Web-api

Thanks again for you two.
This is solved