import java.util.*;
import java.text.*;

class Two
{
    public static void main(String[] args)
    {
        System.out.println("*****请输入日期(格式:2016-01)*****");
        Scanner sc = new Scanner(System.in);
        String scStr = sc.next();

//****** 提取星期 年  月
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date date = new Date();
        try{
            date = sdf.parse(scStr); //输入的字符串转换成日期
        }catch(ParseException e){
        }
        SimpleDateFormat sdfE = new SimpleDateFormat("E");
        String dE = sdfE.format(date); //输入的月份1号 是星期几
        SimpleDateFormat sdfY = new SimpleDateFormat("yyyy");
        String dY = sdfY.format(date);  //提取年
        SimpleDateFormat sdfM = new SimpleDateFormat("MM");
        String dM = sdfM.format(date);  //提取月

//******  将 年 月转换为数字
        int month = 0;    //接收字符串转数字
        int year = 0;
        try{  //捕捉异常处理
            year = Integer.parseInt(dY);
            month = Integer.parseInt(dM);
        }catch(NumberFormatException e){}

        System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");

        switch(month){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
                calendar(dE,31);
                break;
                // 30天
            case 4:
            case 6:
            case 11:
                calendar(dE,30);
                break;
                // 28 或 29天的
            case 2:
                if(year%4==0 && year%100!=0){
                    calendar(dE,29);
                }else {
                    calendar(dE,28);
                }
            break;
            default:
                break;
            
        }

    }

    public static void calendar(String e,int n){
        int a = 0;
        if(e.equals("星期日")){
            a = 0;
        } else if(e.equals("星期一")){
            a = 1;
        }else if(e.equals("星期二")){
            a = 2;
        }else if(e.equals("星期三")){
            a = 3;
        }else if(e.equals("星期四")){
            a = 4;
        }else if(e.equals("星期五")){
            a = 5;
        }else if(e.equals("星期六")){
            a = 6;
        }

        for(int k = 1; k <= a+n; k++){
            if(k<=a){
                System.out.print("*\t");
            }else {
                System.out.print(k-a+"\t");
            }
            if(k%7==0){
                System.out.println();
            }
        
        }
    }
}

运用Date日期来做日历的更多相关文章

  1. Date日期类,Canlendar日历类,Math类,Random随机数学类

    Date日期类,SimpleDateFormat日期格式类 Date  表示特定的时间,精确到毫秒 常用方法 getTime() setTime() before() after() compareT ...

  2. Date日期类 Calendar日历类 完成可视化日历

    package com.test; import java.text.DateFormat; import java.text.ParseException; import java.text.Sim ...

  3. java之Date(日期)、Date格式化、Calendar(日历)

    参考http://how2j.cn/k/date/date-date/346.html Date(日期) Date类 注意:是java.util.Date; 而非 java.sql.Date,此类是给 ...

  4. 常用类--Date日期类,SimpleDateFormat日期格式类,Calendar日历类,Math数学工具类,Random随机数类

    Date日期类 Date表示特定的时间,精确到毫秒; 构造方法: public Data() public Date(long date) 常用方法: public long getTime() pu ...

  5. 【转】Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  6. Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  7. 从.net复制源代码中国农历阵列,必要做日历

    从.net复制源代码中国农历阵列,必要做日历 const { 闰月的月份.春节的阳历日期(农历正月初一).农历的每一个月天数 } c_arrLunarInfo: array [1900 .. 2100 ...

  8. SpringMVC解决@ResponseBody返回Json的Date日期类型的转换问题

    在做项目的时候,发现后台把Date类型的属性以json字符串的形式返回,前台拿不到转换后的日期格式,始终响应回去的都是long类型时间戳. 查阅资料之后找到解决方法: 方法一(在springmvc的x ...

  9. js转换Date日期格式

    有时候做项目会用到js的date日期格式,因为Date()返回的格式不是我们需要的, Date()返回格式: Thu Mar 19 2015 12:00:00 GMT+0800 (中国标准时间) 而我 ...

随机推荐

  1. windows store app Lifecycle

    1.Activated 2.Suspended 3.Resumed 4.Terminated 对应的 js代码: (function () { "use strict"; WinJ ...

  2. UVA 11734 Big Number of Teams will Solve This

    大水题,不解释啦! #include<cstdio> #include<cstring> #define maxn 50 using namespace std; char s ...

  3. Java中对List集合排序的两种方法

    第一种方法,就是list中对象实现Comparable接口,代码如下: public class Person implements Comparable<Person> { privat ...

  4. ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件

    一.简介 1.在onListItemClick()中new Intent,Intent以存储序列化后的mp2Info对象作为参数,启动serivce 2.DownloadService在onStart ...

  5. MySQL学习笔记之一

    MySQL装有一个名为mysql的命令行,在提示符下输入mysql将出现如下的简单提示: ➜ ~ mysql Welcome to the MySQL monitor. Commands end wi ...

  6. Android进阶篇-时间滑动控件

    仿Iphone时间选择滑动控件: WheelView.java: /** * @author Administrator * * 时间滑动滚轮 */ public class WheelView ex ...

  7. 如何查看跟踪查看LINUX内核中的源码

    我的博客:www.while0.com 最近看LINUX书籍时,根据书中代码找相应的函数或者结构定义相当吃力,根据网上资料按以下方法查找速度较快. 1.安装ctags 在源代码目录下运行 ctags ...

  8. Linux 线程优先级

    http://www.cnblogs.com/imapla/p/4234258.html http://blog.csdn.net/lanseshenhua/article/details/55247 ...

  9. 理解Java ClassLoader机制

    当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构: bootstrap classloader                |       extension cla ...

  10. 修改tomcat的部署名称

    找到指定工程下面的.setting目录下面的org.eclipse.wst.common.component文件,可以看到以下的配置 <?xml version="1.0" ...