如何让Java显示从日期开始的日期? [英] How to get Java to show the day of month from a date?
本文介绍了如何让Java显示从日期开始的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试提取今天的日期。我有这个
I am trying to extract the day of month of today's date. I have this
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
JOptionPane.showMessageDialog(null, date.getDay());
但是当出现消息对话框时,它会显示数字 5
,今天是 8
。如何设置它以显示该月的哪一天?
but when the message dialog appears it show the number 5
and today it's the 8
th. How can I set it to show what day of the month it is?
推荐答案
date.getDay( )
返回星期几。星期日是0,同样星期六是6。
date.getDay()
returns the day of the week. sunday is 0 and similarly saturday is 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显示从日期开始的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文