package day01.日期类.Acm; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Scanner; public class test01 { public static void main(String[] args) throws ParseException { System.out.println("请输入日期:(格式:2021-10-8)"); Scanner sc = new Scanner(System.in); String s = sc.nextLine(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date s1 = format.parse(s); Calendar c = new GregorianCalendar(); c.setTime(s1); //时间对象转为日期类 int currentDay = c.get(Calendar.DATE); //当前日期中的当前天 3 c.set(Calendar.DAY_OF_MONTH, 1); //首先设置日期c为每月1号 //获取1号是星期几 int firstDay = c.get(Calendar.DAY_OF_WEEK) - 1; System.out.println("第一天:" + firstDay); //获取总天数 int totalMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println("一t二t三t四t五t六t日"); System.out.println("=========================="); for (int j = 1; j < firstDay; j++) { //当月第一天换行输出 System.out.print("t"); } for (int i = 1; i <= totalMonth; i++) { if (i == currentDay) { System.out.print("*"); } System.out.print(i + "t"); if ((i - (8 - firstDay)) % 7 == 0) { System.out.println(); } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)