时间没有完美显示,我正在尝试显示我的系统时间。
此外,我无法设置这些
int minut = calendar.getTime().getMinutes();
int hours = calendar.getTime().getHours();
int sec = calendar.getTime().getSeconds();
它给出了错误:
The method getSeconds() from the type Date is depreciated.
The method getHours() from the type Date is depreciated.
The method getMinutes() from the type Date is depreciated.
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
int hours = cal.getTime();
int minut = cal.getTime();
hours = hours * 30 + minut / 2;
minut = minut * 6;
int sec = cal.getTime();
minut = minut +sec/10;
sec = sec * 6;
hr.setRotate(hours);
minute.setRotate(minut);
second.setRotate(sec);
Scene sc = new Scene(pane);
ps.setScene(sc);
它给我时间,例如我的系统时间是10:25它显示09:25
答案 0 :(得分:0)
您的代码对我来说没有多大意义,但请记住,Calender.getTimeInMillis()或Date.getTime()会返回UTC时间 - 无论您在日历上设置的时区如何。
答案 1 :(得分:0)
请尝试下面的代码,它会给你正确的时间:
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int millis = now.get(Calendar.MILLISECOND);
System.out.println(hour + ":" + minute + ":" + second + ":" + millis);