控制台输入年月,怎样获取年份月份。
解决方案 »
- dos下如何支持中文啊?
- 请问有经验的专家:当在用Java开发程序时,遇到不能解决问题时(或遇到一种新技术时),该如何解决,有什么更好的方法?
- HELP!!!紧急求救!!关于java描点成线的问题~~~~~~~~~~~
- javamail发邮件在linux下无法发送附件的问题?
- 到http://www.javootoo.com/上下载lookandfeel,没有下载的连接??怎么回事呢?
- Java Mail中设置发件人姓名的问题!急
- 做电力软件的同胞请进来拿分
- 大家帮忙看看这段代码哪里出错了!!!!!!!!!
- 一个使用IBM VIAVOICE的问题
- 编译时不出错,但运行java命令时会出“no classdeffound“,why?
- 新手阶乘问题!求解
- 程序里面,,请问00:00:00 16日,是算今天凌晨00点开始吗?还是今天晚上23,59,59秒后面的一秒?
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;public class YearMonth {
public static void main(String[] args) throws IOException, ParseException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
while (true){
System.out.println("\nPlease input year and month like 1983-05 : ");
String line = reader.readLine();
Date d = format.parse(line);
System.out.println("The year is:"+d.getYear());
System.out.println("The month is:"+d.getMonth());
}
}
}
public static void main(String[] args) throws IOException, ParseException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
while (true){
System.out.println("\nPlease input year and month like 1983-05 : ");
String line = reader.readLine();
Date d = format.parse(line);
Calendar cal =new GregorianCalendar();
cal.setTime(d);
int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println("The amout of day in month is: " + day);
}
}
}
我用set和roll来计算的天数,你用的这个方法要简单多了。非常感谢。