我不知道为什么 Java 几乎不可能做这么简单的事情。我已经尝试了很多在网上找到的解决方案,但似乎没有一个简单干净且有效的解决方案。
这是我最近的解决方案尝试
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println( sdf.format(calendar.getTime()) );
我的异常输出:27/02/2014 17:06:00
我的真实输出:03/03/2014 20:35:44
这有什么意义。
最佳答案
改为在 SimpleDateFormat
实例中设置时区
sdf.setTimezone("America/Los_Angeles");
关于java - 如何在Java中获取您所在时区的当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22084171/