我正在尝试提取今天的日期。我有这个
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
JOptionPane.showMessageDialog(null, date.getDay());
但是当消息对话框出现时,它显示数字5
今天已经是8
了。如何设置它以显示当前是该月的哪一天?
最佳答案
date.getDay()
返回星期几。周日是 0,同样周六是 6。
请参阅java docs
根据下面给出的评论
Calendar cal = Calendar.getInstance();
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
String dayOfMonthStr = String.valueOf(dayOfMonth);
System.out.println(dayOfMonthStr);
关于java - 如何让 Java 显示日期中的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19872693/