powered by Jive Software

How to get time by Time (extends IQ)

hey all, i want to get time, and send Time packet like this

Time timeRequest = new Time();

timeRequest.setType(IQ.Type.GET);

timeRequest.setTo("123456@domain/android);

// Create a packet collector to listen for a response.

PacketCollector collector = con.createPacketCollector(

new PacketIDFilter(timeRequest.getPacketID()));

con.sendPacket(timeRequest);

// Wait up to 5 seconds for a result.

IQ result = (IQ)collector.nextResult(5000);

if (result != null && result.getType() == IQ.Type.RESULT) {

Time timeResult = (Time)result;

// can’t get the time %>_<%

}

receive the packet like this

how can i get the time ? thanks!

First of all, try using SyncPacketSend instead of setting up the PacketCollector and stuff yourself. It makes life a little easier.

As for accessing the time, you just need to call the timeResult.getTime() method.

BTW, the packet you are showing is actually the request, not the response.