当前位置:   article > 正文

android/IOS NTP 获取在线的GMT 网络时间_ios ntp设置

ios ntp设置


不通过读取手机时间,读取服务器时间,通过NTP协议进行获取时间



ios: http://blog.csdn.net/wzq9706/article/details/9497615


android :http://blog.csdn.net/mapdigit/article/details/7669325


也可以从response的headers中获取:


okhttp可以这样获取:


response.headers().get("Date");

上边的是格林时间,可以转成我们自己的北京时区时间


  1. public static void getServerTimeDelta(ResponseInfo<String> responseInfo){
  2. if (responseInfo != null) {
  3. Header headers = responseInfo.getFirstHeader("Date");
  4. String strServerDate = headers.getValue();
  5. if (!TextUtils.isEmpty(strServerDate)){
  6. //Thu, 29 Sep 2016 07:57:42 GMT
  7. final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z",
  8. Locale.ENGLISH);
  9. TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
  10. try {
  11. Date serverDate = simpleDateFormat.parse(strServerDate);
  12. GeexekApplication.ResponseTime = serverDate.getTime();
  13. GeexekApplication.ResponseCurrentTime =SystemClock.elapsedRealtime();
  14. }catch(Exception exception){
  15. exception.printStackTrace();
  16. }
  17. }
  18. }
  19. }







声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/808208
推荐阅读
相关标签
  

闽ICP备14008679号