VMware {code} Community
vijaybhosale
Contributor
Contributor

Problem in Getting VC Server Current time.

Hi,

I am connecting the VC and trying to collect VC server current Time.

The below code snippet returning the client machine time instead of VC server time.

start = this._service.currentTime( this._svcRef );

System.out.println("Service CurrentTime "+start.getTime());

Can some one tell me the exact steps to get VC server time using VI SDK?

Thanks,

Vijay

Reply
0 Kudos
4 Replies
Steve_Jin
Expert
Expert

You code seems fine. How did you tell the return is the client side time?

BTW, Do you run your client on the same machine as the VC server?

Steve JIN, VMware Engineering

Creator of VI Java API: http://vijava.sf.net

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
Steve_Jin
Expert
Expert

You code seems fine. How did you tell the returned time is the client side time?

BTW, are you running the code on the same machine as VC? Thanks!

Steve JIN, VMware Engineering

Creator of VI Java API: http://vijava.sf.net

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
vijaybhosale
Contributor
Contributor

No client machine and VC are in different Time zones.

Reply
0 Kudos
Steve_Jin
Expert
Expert

Just coded a sample for you using VI Java API.

package test;

import java.net.URL;

import com.vmware.vim25.mo.ServiceInstance;

public class ServerTime

{

public static void main(String[] args) throws Exception

{

if(args.length!=3)

{

System.out.println("Usage: java ServerTime <url> " +

"<username> <password>");

return;

}

String urlStr = args[0];

String username = args[1];

String password = args[2];

ServiceInstance si = new ServiceInstance(new URL(urlStr),

username, password, true);

java.util.Calendar cal = si.currentTime();

System.out.println("server time:" + cal.getTime());

si.getServerConnection().logout();

}

}

Steve JIN, VMware Engineering

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos