Java - 如何获取当前年份? [英] Java - How to get current year?
问题描述
我想知道目前的日期和时间。
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.
因此答案可能是yes,也许没有。
So the answer is maybe yes, maybe no.
这篇关于Java - 如何获取当前年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!