java语言获取应用服务器的时间_java如何获得服务器时间

给的信息太少,推断你是CS结构的系统,Client取Server端时间,简单说就是一个信息传递的问题,不知道你现在的CS间传递信息方式,一般有RMI、Soap等等,以RMI为例

=======接口部分===============

import java。

rmi。Remote;

import java。rmi。RemoteException;

public interface IDoRemote extends Remote {

public int getServerTime() throws RemoteException;

}

=======接口实现===============

public class DoRemoteImpl extends UnicastRemoteObject implements IDoRemote {

/**

* @throws RemoteException

*/

protected DoRemoteImpl() throws RemoteException {

super();

}

private static final long serialVersionUID = -8158779541912069375L;

/**

* @see iy。

test。RemoteServer。IDoRemote#getServerTime()

*/

public int getServerTime() throws RemoteException {

return rseInt(new SimpleDateFormat("yyyyMMdd")。

format(new Date()));

// return new Date();

}

========Server端绑定===============

public static void main(String[] args) {

try {

eateRegistry(8808);

DoRemoteImpl Server = new DoRemoteImpl();

bind("//localhost:8808/Date-Server", Server);

} catch ( 。

MalformedURLException me) {

intln("Malformed URL: " + String());

} catch (RemoteException re) {

intln("Remote exception: " + String());

}

}

===========客户端的调用方式============

String url = "//localhost:8808/Date-Server";

IDoRemote RmiObject = (IDoRemote) Naming。

lookup(url);

intln(" Server Date: " + tServerTime());

PS。 如果使用jdk5。0以下版本需要用rmic编译一下

可以搜搜网上相关文档,有很多例子

全部


版权声明:本文为weixin_32705525原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。