Make sure to check out our counterpart too: TrueTime, an NTP library for Swift.
NTP client for Android. Calculate the date and time "now" impervious to manual changes to device clock time.
In certain applications it becomes important to get the real or "true" date and time. On most devices, if the clock has been changed manually, then a new Date()
instance gives you a time impacted by local settings.
Users may do this for a variety of reasons, like being in different timezones, trying to be punctual by setting their clocks 5 – 10 minutes early, etc. Your application or service may want a date that is unaffected by these changes and reliable as a source of truth. TrueTime gives you that.
You can read more about the use case in our blog post.
In a recent conference talk, we explained how the full NTP implementation works with Rx. Check the video and slides out for implementation details.
Also, once we have this information it's valid until the next time you boot your device. This means if you enable the disk caching feature, after a single successful NTP request you can use the information on disk directly without ever making another network request. This applies even across application kills which can happen frequently if your users have a memory starved device.
Take a look at the wiki sidebar which should have a lot of useful information.
The short answer is yes. We're planning a complete rewrite of TrueTime (Version 4). See this branch. We juggle our personal time between doing this rewrite and using TrueTime in its current version. TrueTime is still used in its current form at Instacart by many many users.
As is the case with most open source libraries, maintenance is hard. We've not done a great job at answering the various issues, but we want to do better. We can only ask that you trust that the rewrite is coming and it should make things better. We don't want to spend too much time making changes to the library in its existing state, because the rewrite is the better future for TrueTime.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
java.lang.Object ↳android.text.format.Time Class Overview(概述) The Time class is a faster replacement for the java.util.Calendar and java.util.GregorianCalendar classes. An instance of the Time cl
public class TimeUtils { public static String secondToTime(long second) { long hours = second / 3600;//转换小时数 second = second % 3600;//剩余秒数 long minutes = second / 60;//转换分
1.计时器Timer基本用法,完成倒计时 public class TimeActivity extends AppCompatActivity { private Timer timer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(saved
背景 上周基于LruCache实现了一个缓存,实现逻辑大概如下: //使用剩余内存的1/16作为缓存池的最大值 int size = Runtime.getRuntime().freeMemory() / 16; LruCache<String, String> myCache = new LruCache<String, String>(cacheSize) { protect
最近在开发的过程中使用到了TimePicker,需求是可选择24小时制的时间日期,然后发现设置setIs24HourView(true)之后,再使用TimePicker的getCurrentHour得到的却是12小时制,也就是下午的时间,比如14点会显示为2点,那到底是什么原因呢? 小编在实现的过程中代码如下: /** * 日期选择器弹窗 * @param activity
Android计时器TimerTask,Timer,若要在TimerTask中更新主线程UI,鉴于Android编程模型不允许在非主线程中更新主线程UI,因此需要结合Android的Handler实现在Java的TimerTask中更新主线程UI。 现给出一个简单示例。代码使用标准Java的TimerTask和Timer启动一个计时器Task。该任务每隔2秒更新主线程的UI(在主线程的TextVi
120秒转成:02:00 int time = Constants.box_time; SimpleDateFormat format = new SimpleDateFormat("mm:ss"); String format1 = format.format(new D
private void stopTime() { LogUtils.e("stopTime"); if (timer != null) { timer.cancel(); timer = null; } if (task != null) { task
Timer 跟线程的安全有关,所以我们要用Handler来处理: 代码如下:(此Demo主要是演示camera的self Timer 的功能) package com.example.mytimer; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.
方法一:message+handler package com.time; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget
问题内容: 我正在尝试从一个发送客户类的对象,Activity然后在另一个对象中显示它Activity。 客户类的代码: 我想将其对象从一个对象发送Activity到另一个对象,然后在另一个对象上显示数据Activity。 我该如何实现? 问题答案: 一种选择是让你的自定义类实现该接口,然后可以使用该方法的变体在意图中额外传递对象实例。 伪代码:
问题内容: 我很难找到最简单的方法来针对给定的JSON模式字符串验证JSON字符串(作为参考,这是在Java中运行在Android应用程序中)。 理想情况下,我只想传入JSON字符串和JSON模式字符串,并且它返回关于是否通过验证的布尔值。通过搜索,我发现了以下两个有前途的库可以完成此任务: http://jsontools.berlios.de/ https://github.com/fge/j
问题内容: 我想每隔5秒重复调用一次方法,每当我希望停止该方法的重复调用时,我可能会停止或重新启动该方法的重复调用。 这是一些我真正想要实现的示例代码。在这方面请帮助我,我将非常感谢您。 问题答案: 使用以下命令设置重复任务: 如果您想取消任务,只需调用这里就是您的对象 并且您还可以检查答案下方的评论,他们已经提供了有关此内容的简短信息。
问题内容: 我有一个活动,该活动的TabHost包含一组TabSpec,每个TabSpec都有一个listview,其中包含要由该选项卡显示的项目。创建每个TabSpec时,我设置一个图标以显示在选项卡标题中。 TabSpec是通过以下方法创建的,该方法循环创建适当数量的选项卡: 有几个实例,我希望能够更改程序执行过程中每个选项卡中显示的图标。目前,我正在删除所有选项卡,并再次调用上述代码以重新创
问题内容: 如何通过android app向终端发送命令并获取输出?例如,发送“ ls /”并获取输出以在GUI中将其打印出来? 问题答案: 您必须使用反射来调用android.os.Exec.createSubprocess():
问题内容: 我的应用程序显示了许多自定义对话框,例如“是/否”或“接受/取消决定”,并且在编写代码时,我意识到遵循相同的模式重复了太多代码。 我想建立一个通用类,但我不知道该怎么做,或更确切地说,我不知道该怎么做(接口,抽象类,继承,静态类等)。 这是我目前的课程: } 这就是我需要使用此类时要做的事情: 我敢肯定它是可改进的,但是您怎么能做到呢? 谢谢 问题答案: 首先创建一个Base 来保持的