如果系统日期是当前日期的一年,如何在java中获取今天的日期? [英] How to get today's date in java if system date is one year back of current date?

查看:482
本文介绍了如果系统日期是当前日期的一年,如何在java中获取今天的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的动机是获得当前日期而不关心系统日期。

My motive is to get current date without caring of the system date.

推荐答案

我的建议,如果你真的不能依赖系统时间就是使用时间服务器。 Apache commons有一个非常有用的客户端,可以帮助解决这个问题。网上有很多例子:

My suggestion, if you really can't rely on the system time is to use a time server. Apache commons has a really useful client which will help with the this. There are plenty of examples online:

https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ntp/NTPUDPClient.html

还有许多可用的时间服务器。

There are also numerous available timeservers.

不要试图自己纠正日期代码,这将是脆弱的,如果有人纠正服务器时间将破坏。

Don't be tempted to just correct the date yourself in the code, this will be fragile and will break if someone corrects the server time.

显而易见的,更简单的解决方案是纠正服务器上的时间!

The obvious, and easier, solution is to correct the time on the server though!

这篇关于如果系统日期是当前日期的一年,如何在java中获取今天的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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