Java - 如何使当前日期独立于系统日期? [英] Java - How to get current date independent from system date?

查看:119
本文介绍了Java - 如何使当前日期独立于系统日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当前的日期和时间。

I want to know the current Date and Time.

代码

Calendar.getInstance();

表示运行程序的系统的日期和时间,系统日期可能是错误的。

represents a date and time of the system on which the program is running and the system date can be wrong.

那么无论运行程序的系统的日期和时间如何,我能以何种方式获得正确的当前日期和时间?

So Is there any way by which I can get correct current date and time irrespective of the date and time of the system on which program is running?

推荐答案

如果您在互联网上,您可以询问已知且可信赖的时间来源。如果运行程序的人想要阻止你的程序这样做(比如你给他们一个时间有限的许可证并且他们不想支付更多的时间),他们可能会欺骗或阻止这种连接。

If you're on the internet, you might be able to ask a known and trusted time source. If the person running your program wants to prevent your program from doing that (like if you've given them a time limited license and they don't want to pay for more time), they might spoof or block that connection.

在我所参与的一个项目中,我们在无法篡改的硬件中放置了一个安全,可靠的时间源。它专为加密和许可而设计,并有一个Java库来访问它。对不起,我记不起设备的名称。

On one project I was on, we placed a secure, trusted time source in the hardware that could not be tampered with. It was designed for encryption and licensing, and had a Java library to access it. Sorry, I can't remember the name of the device.

所以答案可能是肯定的,也许不是。

So the answer is maybe yes, maybe no.

这篇关于Java - 如何使当前日期独立于系统日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆