-
2022-03-12 19:00:32
网络时间同步机制
系统版本:android7.1
涉及类
//监控网络时间并更新系统时间策略类 NetworkTimeUpdateService.java //与远程 NTP 服务器连接,获取网络时间 NtpTrustedTime.java //真正接受网络时间的类 SntpClient.java
NetworkTimeUpdateService解析
NetworkTimeUpdateService启动流程
NetworkTimeUpdateService是在SystemServer.java里面的startOtherServices方法中创建的,分别调用NetworkTimeUpdateService的构造方法和systemReady方法,最终网络同步系统时间服务启动完成。
private void startOtherServices() { ... NetworkTimeUpdateService networkTimeUpdater = null; ... //初始化时间同步服务 networkTimeUpdater = new NetworkTimeUpdateService(context); //添加到binder管理 ServiceManager.addService("network_time_update_service", networkTimeUpdater); ... final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; mActivityManagerService.systemReady(new Runnable() { ... try { if (networkStatsF != null) networkStatsF.systemReady(); } catch (Throwable e) { reportWtf("making Network Stats Service ready", e); } ... } }
NetworkTimeUpdateService构造方法解析
主要的工作内容- 创建NtpTrustedTime对象,该对象用于获取网络时间。
- 设置更新时间的广播Intent
- 获取framework/base/core/res/res/value/config.xml中的配置信息
//继承Binder,这样就可以添加到ServiceManager中 public class NetworkTimeUpdateService extends Binder { public NetworkTimeUpdateService(Context context) { mContext = context; //用于连接ntp服务器,获取网络时间 mTime = NtpTrustedTime.getInstance(context); //获取AlarmManager对象,用来设置系统时间 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); //com.android.server.NetworkTimeUpdateService.action.POLL广播 Intent pollIntent = new Intent(ACTION_POLL, null); //设置请求更新时间广播 mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0); //24小时 mPollingIntervalMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpPollingInterval); //1分钟 mPollingIntervalShorterMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpPollingIntervalShorter); //3次 mTryAgainTimesMax = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpRetry); //5秒 mTimeErrorThresholdMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpThreshold); //持有唤醒锁 mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, TAG); } }
systemReady解析
主要的工作内容- 创建sim同步运营商同步时间监听。
- 创建com.android.server.NetworkTimeUpdateService.action.POLL广播监听。
- 创建网络变化广播监听
- 创建带handler的子线程,用于后面获取网络时间和同步时间到系统中
- 发送同步时间广播,执行开机后第一次时间同步
- 设置SettingsObserver对象监听Settings.Global.AUTO_TIME属性变化,就是系统设置里面那个是否开启同步时间的设置项修改的值。
/** Initialize the receivers and initiate the first NTP request */ public void systemRunning() { //注册sim同步时间监听 registerForTelephonyIntents(); //注册com.android.server.NetworkTimeUpdateService.action.POLL广播 registerForAlarms(); //注册网络变化广播 registerForConnectivityIntents(); //创建带handler的子线程 HandlerThread thread = new HandlerThread(TAG); thread.start(); mHandler = new MyHandler(thread.getLooper()); //同步时间 // Check the network time on the new thread mHandler.obtainMessage(EVENT_POLL_NETWORK_TIME).sendToTarget(); //监听Settings.Global.AUTO_TIME变化 mSettingsObserver = new SettingsObserver(mHandler, EVENT_AUTO_TIME_CHANGED); mSettingsObserver.observe(mContext); }
其中registerForTelephonyIntents()要说明下,该方法监听的广播收到会改变mNitzTimeSetTime的值,但是不是更新系统时间,该ACTION_NETWORK_SET_TIME和ACTION_NETWORK_SET_TIMEZONE广播是sim卡同步运营商时间时,设置系统时间后再发出来的,故发送广播之前就同步时间,感兴趣可以在系统源码中搜索下ACTION_NETWORK_SET_TIME广播是哪里发的就可以找到同步的地方了。
private void registerForTelephonyIntents() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIME); intentFilter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); mContext.registerReceiver(mNitzReceiver, intentFilter); } /** Receiver for Nitz time events */ private BroadcastReceiver mNitzReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DBG) Log.d(TAG, "Received " + action); if (TelephonyIntents.ACTION_NETWORK_SET_TIME.equals(action)) { mNitzTimeSetTime = SystemClock.elapsedRealtime(); } else if (TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE.equals(action)) { mNitzZoneSetTime = SystemClock.elapsedRealtime(); } } };
除了sim广播外,其他监听触发后都是给handler发送消息同步时间。先看下NetworkTimeUpdateService中的Handler类。
private class MyHandler extends Handler { public MyHandler(Looper l) { super(l); } @Override public void handleMessage(Message msg) { switch (msg.what) { case EVENT_AUTO_TIME_CHANGED: case EVENT_POLL_NETWORK_TIME: case EVENT_NETWORK_CHANGED: //msg.what表示触发导致的同步时间 onPollNetworkTime(msg.what); break; } } }
最终调用的的onPollNetworkTime方法
onPollNetworkTime方法的主要工作内容:- 判断Settings.Global.AUTO_TIME属性是否不为零,即自动同步时间开关是否打开,若没打开就停止同步流程。
- 调用onPollNetworkTimeUnderWakeLock,执行同步时间策略。
private void onPollNetworkTime(int event) { //判断是否启动时间统同步 // If Automatic time is not set, don't bother. if (!isAutomaticTimeRequested()) return; //获取唤醒锁 mWakeLock.acquire(); try { onPollNetworkTimeUnderWakeLock(event); } finally { mWakeLock.release(); } }
onPollNetworkTimeUnderWakeLock的主要工作内容如下:
- 判断是否sim同步过时间,并且同步的时间间隔不超过24h,是的话停止同步,等待24小时候再同步,防止多次同步。
- ntp没有同步过时间或者距离上次同步时间超过24小时,或者Settings.Global.AUTO_TIME改变,则开始时间同步,否则再等24小时同步时间。
- 调用NtpTrustedTime的forceRefresh方法获取ntp时间。
- 调用NtpTrustedTime的currentTimeMillis方法获取从ntp服务上获取的时间。
- 调用SystemClock.setCurrentTimeMillis将同步的时间设置到系统中。
- 若forceRefresh获取时间失败会另外有3次机会从ntp上获取时间,间隔5秒,三次都失败了则再过24小时同步时间。
private void onPollNetworkTimeUnderWakeLock(int event) { final long refTime = SystemClock.elapsedRealtime(); //sim卡时间同步过,并且同步时时间不到24小时 // If NITZ time was received less than mPollingIntervalMs time ago, // no need to sync to NTP. if (mNitzTimeSetTime != NOT_SET && refTime - mNitzTimeSetTime < mPollingIntervalMs) { resetAlarm(mPollingIntervalMs); return; } final long currentTime = System.currentTimeMillis(); if (DBG) Log.d(TAG, "System time = " + currentTime); //没有同步过时间,或者上次时间同步超过24小时,或者Settings.Global.AUTO_TIME属性改变引起的 // Get the NTP time if (mLastNtpFetchTime == NOT_SET || refTime >= mLastNtpFetchTime + mPollingIntervalMs || event == EVENT_AUTO_TIME_CHANGED) { if (DBG) Log.d(TAG, "Before Ntp fetch"); //距上次同步时间过了24小时获取没有同步过 // force refresh NTP cache when outdated if (mTime.getCacheAge() >= mPollingIntervalMs) { //重新获取网络时间 mTime.forceRefresh(); } //距离上次时间小于24小时,说明同步时间成功,24小时内同步过一次 // only update when NTP time is fresh if (mTime.getCacheAge() < mPollingIntervalMs) { //获取ntp时间 final long ntp = mTime.currentTimeMillis(); mTryAgainCounter = 0; // If the clock is more than N seconds off or this is the first time it's been // fetched since boot, set the current time. if (Math.abs(ntp - currentTime) > mTimeErrorThresholdMs || mLastNtpFetchTime == NOT_SET) { // Set the system time if (DBG && mLastNtpFetchTime == NOT_SET && Math.abs(ntp - currentTime) <= mTimeErrorThresholdMs) { Log.d(TAG, "For initial setup, rtc = " + currentTime); } if (DBG) Log.d(TAG, "Ntp time to be set = " + ntp); // Make sure we don't overflow, since it's going to be converted to an int if (ntp / 1000 < Integer.MAX_VALUE) { //设置系统时间 SystemClock.setCurrentTimeMillis(ntp); } } else { if (DBG) Log.d(TAG, "Ntp time is close enough = " + ntp); } //更新mLastNtpFetchTime属性 mLastNtpFetchTime = SystemClock.elapsedRealtime(); } else { //说明同步时失败,没5秒同步一次,同步三次,三次后再过24小时 // Try again shortly mTryAgainCounter++; if (mTryAgainTimesMax < 0 || mTryAgainCounter <= mTryAgainTimesMax) { resetAlarm(mPollingIntervalShorterMs); } else { // Try much later mTryAgainCounter = 0; resetAlarm(mPollingIntervalMs); } return; } } resetAlarm(mPollingIntervalMs); }
NtpTrustedTime与SntpClient解析
前面已经研究完同步策略了,下面讲下,如何系统是如何与ntp服务器联系并且获取到网络时间的。先讲下NtpTrustedTime,该类是个单例,所以从它的getInstance方法讲起。主要做如下工作:
- 获取ntp服务器的地址和连接超时时间。
- 创建NtpTrustedTime对象,将ntp服务器的地址和连接超时时间和地址传入进去。
private NtpTrustedTime(String server, long timeout) { if (LOGD) Log.d(TAG, "creating NtpTrustedTime using " + server); mServer = server; mTimeout = timeout; } public static synchronized NtpTrustedTime getInstance(Context context) { if (sSingleton == null) { final Resources res = context.getResources(); final ContentResolver resolver = context.getContentResolver(); //默认ntp服务器地址 2.android.pool.ntp.org final String defaultServer = res.getString( com.android.internal.R.string.config_ntpServer); //5秒 final long defaultTimeout = res.getInteger( com.android.internal.R.integer.config_ntpTimeout); final String secureServer = Settings.Global.getString( resolver, Settings.Global.NTP_SERVER); final long timeout = Settings.Global.getLong( resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout); final String server = secureServer != null ? secureServer : defaultServer; sSingleton = new NtpTrustedTime(server, timeout); sContext = context; } return sSingleton; }
解析获取网络时间方法forceRefresh,主要工作如下:
- 判断设备是否有网。
- 创建SntpClient对象,用于获取网络时间的。
- 向ntp请求网络时间。
- 获取网络请求的时间进行保存。
public boolean forceRefresh() { ... //设备是否有网 final NetworkInfo ni = mCM == null ? null : mCM.getActiveNetworkInfo(); if (ni == null || !ni.isConnected()) { if (LOGD) Log.d(TAG, "forceRefresh: no connectivity"); return false; } if (LOGD) Log.d(TAG, "forceRefresh() from cache miss"); //创建SntpClient对象,用于获取网络时间的 final SntpClient client = new SntpClient(); //向ntp请求网络时间 if (client.requestTime(mServer, (int) mTimeout)) { //表示有缓冲 mHasCache = true; //将SntpClient获取的网络时间同步过来 mCachedNtpTime = client.getNtpTime(); //记录相应ntp后的机器开机后的时间 mCachedNtpElapsedRealtime = client.getNtpTimeReference(); mCachedNtpCertainty = client.getRoundTripTime() / 2; return true; } else { return false; } }
NetworkTimeUpdateService中有调用NtpTrustedTime的getCacheAge和currentTimeMillis,我们依次解析下
public long getCacheAge() { //mHasCache为false表示之前没有同步过时间 if (mHasCache) { //获取距离上次同步时间的间隔 return SystemClock.elapsedRealtime() - mCachedNtpElapsedRealtime; } else { return Long.MAX_VALUE; } } public long currentTimeMillis() { if (!mHasCache) { throw new IllegalStateException("Missing authoritative time source"); } if (LOGD) Log.d(TAG, "currentTimeMillis() cache hit"); //计算出当前时间放回给调用者。 // current time is age after the last ntp cache; callers who // want fresh values will hit makeAuthoritative() first. return mCachedNtpTime + getCacheAge(); }
最后解析下SntpClient对象,真正与ntp服务其对接的逻辑都在这个类里面,才有socket通信。该类构造方法是默认构造方法,没有自己定义,我们直接解析它的requestTime方法。主要内容
- 根据host地址创建InetAddress对象。
- 创建DatagramSocket对象,用于ntp服务器通讯。
- 创建请求对象DatagramPacket的类对象request。
- 调用DatagramSocket对象的send方法,将请求传递给ntp服务器。
- 创建接收ntp服务器信息的DatagramPacket的类对象response。
- 调用socket.receive方法,将ntp服务器里的信息传递给response。
- response里面的信息赋值給SntpClient各个参数,供NtpTrustedTime调用。
public boolean requestTime(String host, int timeout) { InetAddress address = null; try { //根据host创建网络地址 address = InetAddress.getByName(host); } catch (Exception e) { if (DBG) Log.d(TAG, "request time failed: " + e); return false; } //设置地址和端口以及超时时间 return requestTime(address, NTP_PORT, timeout); } public boolean requestTime(InetAddress address, int port, int timeout) { DatagramSocket socket = null; try { //创建数据报socket对象 socket = new DatagramSocket(); socket.setSoTimeout(timeout); byte[] buffer = new byte[NTP_PACKET_SIZE]; //创建请求 DatagramPacket request = new DatagramPacket(buffer, buffer.length, address, port); // set mode = 3 (client) and version = 3 // mode is in low 3 bits of first byte // version is in bits 3-5 of first byte buffer[0] = NTP_MODE_CLIENT | (NTP_VERSION << 3); // get current time and write it to the request packet final long requestTime = System.currentTimeMillis(); final long requestTicks = SystemClock.elapsedRealtime(); writeTimeStamp(buffer, TRANSMIT_TIME_OFFSET, requestTime); //发送请求 socket.send(request); // read the response DatagramPacket response = new DatagramPacket(buffer, buffer.length); //获取服务返回数据 socket.receive(response); //设置参数 final long responseTicks = SystemClock.elapsedRealtime(); final long responseTime = requestTime + (responseTicks - requestTicks); // extract the results final byte leap = (byte) ((buffer[0] >> 6) & 0x3); final byte mode = (byte) (buffer[0] & 0x7); final int stratum = (int) (buffer[1] & 0xff); final long originateTime = readTimeStamp(buffer, ORIGINATE_TIME_OFFSET); final long receiveTime = readTimeStamp(buffer, RECEIVE_TIME_OFFSET); final long transmitTime = readTimeStamp(buffer, TRANSMIT_TIME_OFFSET); /* do sanity check according to RFC */ // TODO: validate originateTime == requestTime. checkValidServerReply(leap, mode, stratum, transmitTime); long roundTripTime = responseTicks - requestTicks - (transmitTime - receiveTime); // receiveTime = originateTime + transit + skew // responseTime = transmitTime + transit - skew // clockOffset = ((receiveTime - originateTime) + (transmitTime - responseTime))/2 // = ((originateTime + transit + skew - originateTime) + // (transmitTime - (transmitTime + transit - skew)))/2 // = ((transit + skew) + (transmitTime - transmitTime - transit + skew))/2 // = (transit + skew - transit + skew)/2 // = (2 * skew)/2 = skew long clockOffset = ((receiveTime - originateTime) + (transmitTime - responseTime))/2; if (DBG) { Log.d(TAG, "round trip: " + roundTripTime + "ms, " + "clock offset: " + clockOffset + "ms"); } // save our results - use the times on this side of the network latency // (response rather than request time) mNtpTime = responseTime + clockOffset; mNtpTimeReference = responseTicks; mRoundTripTime = roundTripTime; } catch (Exception e) { if (DBG) Log.d(TAG, "request time failed: " + e); return false; } finally { if (socket != null) { socket.close(); } } return true; }
更多相关内容 -
电脑时间同步,小编教你怎么让电脑时间和网络时间同步
2021-06-22 22:38:13对于怎么让电脑时间和网络时间同步这个问题,小编觉得是我们要学会的,因为我们或许会经常遇到这样的问题,所以还是预防一下为好。下面小编就来和你们说说怎么让电脑时间和网络时间同步。有的时候我们会发现电脑的...对于怎么让电脑时间和网络时间同步这个问题,小编觉得是我们要学会的,因为我们或许会经常遇到这样的问题,所以还是预防一下为好。下面小编就来和你们说说怎么让电脑时间和网络时间同步。
有的时候我们会发现电脑的时间和网络的时间是不同的,那这是要怎么让它们同步起来呢?小编接下来就告诉你们怎么让电脑时间和网络时间同步起来,小伙伴们快和小编一起去接着往下看看吧。
首先,点击桌面上右下的时间,弹出框点击更改时间和日期。
电脑时间和网络时间同步图-1
接着,在弹出框中选择“Internet时间”。
网络时间图-2
下一步,选择“Internet时间”选项,点击“更改设置”,点击立即更新。
时间同步图-3
时间同步图-4
然后会提示超时出错,这个时候去看一下服务里面的window Time 服务时候开启,我的电脑手表邮件选择管理。
电脑时间和网络时间同步图-5
接着,找到“window Time”发现是关闭开启,调成自动启动的服务这样就不用每次去修改时间了。
电脑时间和网络时间同步图-6
电脑时间和网络时间同步图-7
最后就会发现时间和日期都同步了~~~
电脑时间和网络时间同步图-8
-
CentOS7 时间与网络时间同步
2022-02-07 13:47:302、设置系统时间与网络时间同步 ntpdate 0.asia.pool.ntp.org 这里主要就是通过时间服务器对系统时间进行同步,所以0.asia.pool.ntp.org并不是固定的,大家可以选择time.nist.gov、time.nuri.net、0.asia.pool.ntp...问题描述:使用date命令查看之后,发现时间与本地时间不一致
三步解决方法:
1、安装ntpdate工具
yum -y install ntp ntpdate
2、设置系统时间与网络时间同步
ntpdate 0.asia.pool.ntp.org
这里主要就是通过时间服务器对系统时间进行同步,所以0.asia.pool.ntp.org并不是固定的,大家可以选择time.nist.gov、time.nuri.net、0.asia.pool.ntp.org、1.asia.pool.ntp.org、2.asia.pool.ntp.org、3.asia.pool.ntp.org中任意一个,只要保证可用就OK。
3、将系统时间写入硬件时间
hwclock --systohc
timedatectl
4.强制系统时间写入CMOS中防止重启失效
hwclock -w
或clock -w -
Android中的网络时间同步
2018-11-03 21:39:08研究的结果让我感到惊讶,Android的网络时间同步居然与SNTP协议无关,甚至与TCP/IP协议也毫无关系。 从设置的应用程序中可以了解到,自动同步网络时间的选项只是修改了Settings.System.AUTO_TIME这个设置: private ...分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
在 Android的系统设置中,有自动同步网络时间的选项。因为Broncho A1移植到froyo版本之后,我们发现时间同步选项无效了。所以我花了一点时间去研究 Android的网络时间同步的流程。研究的结果让我感到惊讶,Android的网络时间同步居然与SNTP协议无关,甚至与TCP/IP协议也毫无关系。
从设置的应用程序中可以了解到,自动同步网络时间的选项只是修改了Settings.System.AUTO_TIME这个设置:
private void setAutoState(boolean isEnabled, boolean autotimeStatus) { if (isEnabled == false) { mAutoPref.setChecked(autotimeStatus); mAutoPref.setEnabled(isEnabled); } else { Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME, autotimeStatus ? 1 : 0); } mTimePref.setEnabled(!autotimeStatus); mDatePref.setEnabled(!autotimeStatus); mTimeZone.setEnabled(!autotimeStatus); }
谁会用这个设置呢?然后从代码中查找Settings.System.AUTO_TIME,主要有下面两处:
telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.javatelephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
GSM和CDMA的实现应该是类似的,这里只是看看GSM:1. reference-ril/reference-ril.c处理主动上报消息。
if (strStartsWith(s, "%CTZV:")) { /* TI specific -- NITZ time */ char *response; line = p = strdup(s); at_tok_start(&p); err = at_tok_nextstr(&p, &response); free(line); if (err != 0) { LOGE("invalid NITZ line %s/n", s); } else { RIL_onUnsolicitedResponse ( RIL_UNSOL_NITZ_TIME_RECEIVED, response, strlen(response)); }}这里是处理模组主动上报的消息,如果是时间和时区消息,则调用RIL_onUnsolicitedResponse。2. RIL_onUnsolicitedResponse会把消息发送给RIL的客户端。
ret = sendResponse(p, client_id);
时间和时区信息的格式在RIL_UNSOL_NITZ_TIME_RECEIVED消息的定义处有说明: "data" is const char * pointing to NITZ time string in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt"3. RIL客户端处理RIL_UNSOL_NITZ_TIME_RECEIVED消息(telephony/java/com/android/internal/telephony/RIL.java: processUnsolicited)case RIL_UNSOL_NITZ_TIME_RECEIVED: if (RILJ_LOGD) unsljLogRet(response, ret); // has bonus long containing milliseconds since boot that the NITZ // time was received long nitzReceiveTime = p.readLong(); Object[] result = new Object[2]; result[0] = ret; result[1] = Long.valueOf(nitzReceiveTime); if (mNITZTimeRegistrant != null) { mNITZTimeRegistrant .notifyRegistrant(new AsyncResult (null, result, null)); } else { // in case NITZ time registrant isnt registered yet mLastNITZTimeInfo = result; }
是GsmServiceStateTracker向RIL注册的,所以事件会由GsmServiceStateTracker来处理。4. GsmServiceStateTracker 处理EVENT_NITZ_TIME事件:case EVENT_NITZ_TIME: ar = (AsyncResult) msg.obj; String nitzString = (String)((Object[])ar.result)[0]; long nitzReceiveTime = ((Long)((Object[])ar.result)[1]).longValue(); setTimeFromNITZString(nitzString, nitzReceiveTime); break;
这里nitzString是时间字符串,由setTimeFromNITZString负责解析。private void setTimeFromNITZString (String nitz, long nitzReceiveTime) { String[] nitzSubs = nitz.split("[/:,+-]"); int year = 2000 + Integer.parseInt(nitzSubs[0]); c.set(Calendar.YEAR, year); // month is 0 based! int month = Integer.parseInt(nitzSubs[1]) - 1; c.set(Calendar.MONTH, month); int date = Integer.parseInt(nitzSubs[2]); c.set(Calendar.DATE, date); int hour = Integer.parseInt(nitzSubs[3]); c.set(Calendar.HOUR, hour); int minute = Integer.parseInt(nitzSubs[4]); c.set(Calendar.MINUTE, minute);
如果在系统设置中,用户选择了自动同步网络时间,才会去设置系统时间。if (getAutoTime()) { setAndBroadcastNetworkSetTimeZone(zone.getID()); } if (getAutoTime()) {setAndBroadcastNetworkSetTime(c.getTimeInMillis()); }
关于NITZ在WIKI上有说明:NITZ, or Network Identity and Time Zone[1], is a mechanism for provisioning local time and date, as well as network provider identity information to mobile devices via a wireless network[2]. NITZ has been part of the official GSM standard since phase 2+ release 96[3]. NITZ is often used to automatically update the system clock of mobile phones.由于NITZ的实现是可选的,如果运营商不支持它,Android手机就无法使用此功能了。此时用最好用SNTP来代替,否则用户会感到迷惑。但Android目前好像并没有这样做,我只找到两处地方调用SntpClient,但它们都没有去设置系统时间。给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
-
视频监控系统网络时间同步(NTP网络授时)问题详解
2019-05-08 18:15:22视频监控系统是指综合应用视音频监控、通信、计算机网络等技术监视设防区域,并实时显示、记录现场图像的电子系统或网络。系统可以在非常事件突发时,及时地将叠加有时间、地点等信息内容的现场情况记录下来,以便... -
Ubuntu系统时间与网络时间同步
2020-01-04 15:58:19Ubuntu系统时间与网络时间同步 sudo dpkg-reconfigure tzdata -
Android 系统当前时间与网络时间同步
2020-04-30 13:25:51在开发系统设置时,需要手动设置系统时间和使用网络时间来进行同步,这时候就需要来获取网络时间进行设置了 代码如下: URL url = new URL("http://www.baidu.com");//取得资源对象 URLConnection uc = url.open... -
linux设置系统时间与网络时间同步
2019-05-31 18:46:45#date 查看当前系统时间 第一种方法:#date -s "05/01/2019 12:20" 手动更改系统时间为5月1号12:20 第二种方法:#yum -y install chronyd #systemctl enable chronyd #vi /etc/chrony.conf 将server …………... -
西门子PLC如何设NTP网络时间同步(全解)
2021-12-02 17:22:46西门子PLC如何设NTP网络时间同步(全解) -
CentOS7设置系统时间与网络时间同步
2018-04-04 13:37:51Linux的时间分为System Clock(系统时间)和Real Time Clock(硬件时间,简称RTC)系统时间:指当前Linux Kernel中的时间;硬件时间:指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。l 查看系统时间:... -
计算机网络时间同步(时钟同步)的重要性
2018-09-12 10:42:00计算机网络时间同步(时钟同步)的重要性 本文由北京华人开创科技公司提供 要转载需授权 授权联系159-0109-2122 微 -
CentOS设置系统时间与网络时间同步
2017-03-17 17:08:34Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。 系统时间:指当前Linux Kernel中的时间。 硬件时间:主板上有电池供电的时间。 查看系统时间的命令: #date 设置系统时间的... -
ubuntu设置系统时间与网络时间同步
2017-11-26 15:55:29Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。系统时间:指当前Linux Kernel中的时间。硬件时间:主板上有电池供电的时间。查看系统时间的命令: #date设置系统时间的命令: #... -
计算机网络时间同步技术原理介绍
2019-01-24 17:48:23由计算机网络系统组成的分布式系统,若想协调一致进行:IT行业的“整点开拍”、“秒杀”、“Leader选举”,通信行业的“同步组网”之类业务处理,毫秒级甚至微秒级的时间同步是重要基础之一。 2.术语描述 2.0 世界... -
centos7网络时间同步
2018-07-21 13:45:40centos7网络时间同步 1. 安装ntpdate工具 yum -y install ntp ntpdate 2. 设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org 3. 将系统时间写入硬件时间 hwclock --systohc ok!!!!... -
设置CentOS7时间与网络时间同步
2020-09-25 10:22:06我们在安装CentOS系统时,如果没有配置好系统时间,可能就与本地时间不一致,如果是分布式集群部署的情况,时间不一致会出现很多问题,下面来分享把如何设置系统时间与网络时间同步,这样各个系统时间都能保持一致了... -
电脑时间与网络时间不同步解决办法
2021-06-23 00:40:21该楼层疑似违规已被系统折叠隐藏此楼查看此楼电脑系统时间同步更新时提示“RPC服务器不可用”解决办法原因1:电脑本身的时间和网络时间相差太大原因2:windows time 服务没有开启或者运行不正常 重新开启它在对电脑... -
Ubuntu设置系统时间与网络时间同步
2017-12-17 10:02:29Linux默认情况下使用UTC格式作为标准时间格式,如果在Linux下运行程序,且在程 序中指定了与系统不一样的时区的时候,可能会造成时间错误。如果是Ubuntu的桌面版,则可以直接在图形模式下修改时区信息,但如果是在... -
centos7设置系统时间与网络时间同步
2018-11-05 10:50:34Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。 系统时间:指当前Linux Kernel中的时间。 硬件时间:主板上有电池供电的时间。 查看系统时间的命令: #date 设置系统时间的... -
国内外常用公共NTP网络时间同步服务器地址
2018-09-10 10:53:22HSDN(Home Server Data Network)本地服务器数据网络 企业 阿里巴巴 腾讯 微软 苹果 谷歌 Facebook Cloudflare 高通 Hurricane Electric 飓风电气 MSK-IX(Moscow Internet eXchange) 莫斯科网络交换 ... -
通信系统中各网络设备时间同步要求
2020-04-30 17:10:52传统TDM有两个主要的应用,语音业务和时钟同步业务。 在传统的通讯网络结构中,固网的TDM业务主要是语音业务。如果承载网络两端的时钟不一致,长期积累后会造成滑码。ITU-T在G.823中定义了对固网TDM业务的需求和... -
如何使用timedatectl从命令行设置时区并启用网络时间同步(NTP)
2020-09-12 17:27:35本文介绍了如何使用timedatectl更改时区,以及如何使用Linux上的NTP(网络时间协议)与远程服务器自动同步系统时钟。timedatectl是systemd的一部分,可作为命令行实用程序使用,它允许更改系统时钟的各种设置。 ... -
NTP时间同步客户端程序C#源码
2016-02-15 11:33:39NTP时间同步客户端程序,这是完整源码, -
Linux - 自动同步网络时间
2021-04-28 14:11:23查看系统时间 执行 date 命令可以查看当前系统的时间: 原文:Linux - 查看、修改、更新系统时间(自动同步网络时间) 手动修改系统时间 (1)执行如下命令可以设置一个新的系统时间: date -s "20190712 18:30:50" ... -
WiFi之网络时间同步
2017-11-01 13:37:11[RK3288][Android6.0] WiFi之同步网络时间过程 [RK3288][Android6.0] WiFi之网络时间定期同步更新 -
android网络时间同步总结
2014-08-09 22:08:03本文转自:... 最近看了下网络时间同步,总结一下。 整体描述: android网络时间同步使用NITZ(Network identity and Time Zone)运营商可选服务。 由Ril层主动上报RIL_UNSOL_NITZ_TIME_REC -
Ubuntu如何同步网络时间
2019-05-21 16:01:32Ubuntu如何同步网络时间 装完Ubuntu设置完时间,重启总是恢复设置前的时间。 设定时区:dpkg-reconfigure tzdata 选择Asia -> 再选择Shanghai -> OK 解决方法: 1.安装ntpdate工具 sudo apt-get install ... -
windows7 internet系统时间同步出错超时怎么办?国内NTP时间同步服务器地址
2021-01-11 20:11:56下面跟我一起来解决win7 Internet系统时间同步出错的这个问题吧,顺便给大家一些速度比较快的国内NTP时间同步服务器地址,以便大家成功同步系统时间。windows 7系统 Internet 系统时间同步出错...