输入年月日,获取当月日历
来源:互联网 发布:mac口红是哪个国家的 编辑:程序博客网 时间:2024/05/21 05:41
<span style="font-family:Times New Roman;">import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Scanner;//输入年月日,获取当月日历</span>
<span style="font-family:Times New Roman;">public class MyCalendar2{//public static final int YEAR_ =2000;//public static final int MONTH_ = 2;//public static final int DAY_ = 6;public static void main(String[] args) {//输入年、月、日System.out.println( "请输入 年、月、日:" );Scanner in = new Scanner(System.in);int YEAR_= in.nextInt();int MONTH_= in.nextInt();int DAY_= in.nextInt();in.close();GregorianCalendar now = new GregorianCalendar();now.set(Calendar.YEAR, YEAR_);now.set(Calendar.MONTH, MONTH_-1);now.set(Calendar.DAY_OF_MONTH, DAY_);int year_ = now.get(Calendar.YEAR) ;int month_ = now.get(Calendar.MONTH)+1 ; //不太明白为何加1才能得到所需月份?int day_ = now.get(Calendar.DAY_OF_MONTH) ;Date date = now.getTime();System.out.println( "date:"+date.toString() );System.out.println( " year_:"+year_+" month_:"+month_+" day_:"+ day_ );now.set(Calendar.DAY_OF_MONTH, 1);//该月第一天 day置为1int week = now.get(Calendar.DAY_OF_WEEK);// now 是一周的第几天System.out.println( " 是一周的第"+week+"天 ");System.out.println(" Sun Mon Tue Wed Thu Fri Sat");for (int i = Calendar.SUNDAY; i < week; i++) {System.out.print(" ");//找到当月1号的位置}while (now.get(Calendar.MONTH) == month_-1) {int day = now.get(Calendar.DAY_OF_MONTH);//从1号开始if (day < 10) {if (day == day_)System.out.print(" -" + day + "- ");elseSystem.out.print(" " + day + " ");} else {if (day == day_)System.out.print("-" + day + "- ");elseSystem.out.print(" " + day + " ");}if (week == Calendar.SATURDAY) {// 周六换行System.out.println();}now.add(Calendar.DAY_OF_MONTH, 1);week = now.get(Calendar.DAY_OF_WEEK);}}}</span>
0 0
- 输入年月日,获取当月日历
- 日常练习,根据输入的年月获取当月的日历
- 输入年月,得到当月日历
- 获取当前时间,及当月日历
- 输入年月获取当月天数
- 当月日历
- java 输出当月日历
- 输出当月的日历
- java输出当月日历
- 打印当月日历
- js生成当月日历
- jsp当月日历
- 接收用户输入的年月(1990年以后),在控制台中输出当月日历。
- 通过用户输入的年份与月份来算显示当月的日历
- 根据日期获得当月日历
- Oracle实现当月日历显示
- SQL SERVER 实现当月日历
- 显示当月日历-Java实现
- IOC容器是什么
- wcf:数据太多如何实现分页的效果
- linux中fork()和vfork()函数的使用和区别
- 改变对话框背景色,对话框内文本的颜色与背景色
- Listview的onItemClickListener无法响应的问题
- 输入年月日,获取当月日历
- SpringMVC的@ResponseBody乱码
- openlog(),系统信息记录
- Linux 命令
- Java日志管理:Logger.getLogger()和LogFactory.getLog()的区别(详解Log4j)
- Android中如何做到Service被关闭后又自动启动
- Android Service 服务(一)—— Service
- Android之完美退出方法
- OTTO-EVENTBUS