当前位置: 首页>>代码示例>>Java>>正文


Java TimeInfo.getReturnTime方法代码示例

本文整理汇总了Java中org.apache.commons.net.ntp.TimeInfo.getReturnTime方法的典型用法代码示例。如果您正苦于以下问题:Java TimeInfo.getReturnTime方法的具体用法?Java TimeInfo.getReturnTime怎么用?Java TimeInfo.getReturnTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.ntp.TimeInfo的用法示例。


在下文中一共展示了TimeInfo.getReturnTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNTPDate

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
public static String getNTPDate() {

		String[] hosts = new String[] { "ntp02.oal.ul.pt", "ntp04.oal.ul.pt",
				"ntp.xs4all.nl", "time.foo.com", "time.nist.gov" };

		NTPUDPClient client = new NTPUDPClient();
		// We want to timeout if a response takes longer than 5 seconds
		client.setDefaultTimeout(2000);
		SimpleDateFormat OutPutFormat = new SimpleDateFormat(
				"dd/M/yyyy HH:mm:ss", java.util.Locale.getDefault());
		for (String host : hosts) {
			try {
				InetAddress hostAddr = InetAddress.getByName(host);
				TimeInfo info = client.getTime(hostAddr);
				Date date = new Date(info.getReturnTime());
				String out = OutPutFormat.format(date);
				return out;
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		client.close();
		return null;
	}
 
开发者ID:AmulaySoftGroup,项目名称:TaBeTa,代码行数:25,代码来源:GameActivity.java

示例2: getTime

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
/**
 * Queries the given timeserver <code>hostname</code> and returns the time
 * in milliseconds.
 * 
 * @param hostname the timeserver to query
 * @return the time in milliseconds or the current time of the system if an
 * error occurs.
 */
protected static long getTime(String hostname) {
	
	try {
		NTPUDPClient timeClient = new NTPUDPClient();
		timeClient.setDefaultTimeout(NTP_TIMEOUT);
		InetAddress inetAddress = InetAddress.getByName(hostname);
		TimeInfo timeInfo = timeClient.getTime(inetAddress);
		
		return timeInfo.getReturnTime();
	} 
	catch (UnknownHostException uhe) {
		logger.warn("the given hostname '{}' of the timeserver is unknown -> returning current sytem time instead", hostname);
	}
	catch (IOException ioe) {
		logger.warn("couldn't establish network connection [host '{}'] -> returning current sytem time instead", hostname);
	}
	
	return System.currentTimeMillis();
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:28,代码来源:NtpBinding.java

示例3: getTime

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
/**
 * Queries the given timeserver <code>hostname</code> and returns the time
 * in milliseconds.
 *
 * @param hostname the timeserver to query
 * @return the time in milliseconds or the current time of the system if an
 *         error occurs.
 */
protected static long getTime(String hostname) {

    try {
        NTPUDPClient timeClient = new NTPUDPClient();
        timeClient.setDefaultTimeout(NTP_TIMEOUT);
        InetAddress inetAddress = InetAddress.getByName(hostname);
        TimeInfo timeInfo = timeClient.getTime(inetAddress);

        return timeInfo.getReturnTime();
    } catch (UnknownHostException uhe) {
        logger.warn("the given hostname '{}' of the timeserver is unknown -> returning current sytem time instead",
                hostname);
    } catch (IOException ioe) {
        logger.warn("couldn't establish network connection [host '{}'] -> returning current sytem time instead",
                hostname);
    }

    return System.currentTimeMillis();
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:28,代码来源:NtpBinding.java

示例4: getNTPDate

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
public static Date getNTPDate() throws Exception{
    //FIXME: how to use system defined proxy here ?
    System.setProperty("java.net.useSystemProxies", "true");
    NTPUDPClient client = new NTPUDPClient();
    client.setDefaultTimeout(5000);
    TimeInfo response = client.getTime(InetAddress.getByName("pool.ntp.org"));
    return new Date(response.getReturnTime());
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:9,代码来源:SignUtils.java


注:本文中的org.apache.commons.net.ntp.TimeInfo.getReturnTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。