package com.date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class PanduanZhouWu {
public static void main(String[] args) throws java.text.ParseException{
// 获取系统日期
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int yue = c.get(Calendar.MONTH) + 1;
Date date = new Date(Integer.parseInt(new SimpleDateFormat("yyyy")
.format(new Date())), yue, 0);
System.out.println("当前月份的天数:"
+ new SimpleDateFormat("dd").format(date));
// 判断本月的第一天是周几
String _01 = new SimpleDateFormat("yyyy-MM-dd E").format(new Date(
year - 1900, yue - 1, 1));
// 判断本月的最后一天是周几
String _30$31 = new SimpleDateFormat("yyyy-MM-dd E")
.format(new Date(year - 1900, yue - 1, Integer
.parseInt(new SimpleDateFormat("dd").format(date))));
// 获取本月的第一天
int jiequ_tian = Integer.parseInt(_01.substring(8, 10));
// 获取本月的最后一天
int jiequ_tians = Integer.parseInt(_30$31.substring(8, 10));
int tongji = 0;
for (int i = 1; i <= jiequ_tians; i++) {
String aa = _01.replaceAll(_01.substring(8, 10),
String.valueOf(i));
if (aa.length() == 12) {
aa = aa.replaceAll(aa.substring(0, 3), String.valueOf(year));
} else if (aa.length() == 14) {
aa = aa.replaceAll(aa.substring(0, 4), String.valueOf(year));
}
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd E");
Date dates = sim.parse(aa);
if ("星期五".equals(sim.format(dates).substring(11))) {
tongji++;
}
}
System.out.println(yue + "月共有" + tongji + "个周五");
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class PanduanZhouWu {
public static void main(String[] args) throws java.text.ParseException{
// 获取系统日期
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int yue = c.get(Calendar.MONTH) + 1;
Date date = new Date(Integer.parseInt(new SimpleDateFormat("yyyy")
.format(new Date())), yue, 0);
System.out.println("当前月份的天数:"
+ new SimpleDateFormat("dd").format(date));
// 判断本月的第一天是周几
String _01 = new SimpleDateFormat("yyyy-MM-dd E").format(new Date(
year - 1900, yue - 1, 1));
// 判断本月的最后一天是周几
String _30$31 = new SimpleDateFormat("yyyy-MM-dd E")
.format(new Date(year - 1900, yue - 1, Integer
.parseInt(new SimpleDateFormat("dd").format(date))));
// 获取本月的第一天
int jiequ_tian = Integer.parseInt(_01.substring(8, 10));
// 获取本月的最后一天
int jiequ_tians = Integer.parseInt(_30$31.substring(8, 10));
int tongji = 0;
for (int i = 1; i <= jiequ_tians; i++) {
String aa = _01.replaceAll(_01.substring(8, 10),
String.valueOf(i));
if (aa.length() == 12) {
aa = aa.replaceAll(aa.substring(0, 3), String.valueOf(year));
} else if (aa.length() == 14) {
aa = aa.replaceAll(aa.substring(0, 4), String.valueOf(year));
}
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd E");
Date dates = sim.parse(aa);
if ("星期五".equals(sim.format(dates).substring(11))) {
tongji++;
}
}
System.out.println(yue + "月共有" + tongji + "个周五");
}
}
/*
如果判断其他的周几,可以将
if ("星期五".equals(sim.format(dates).substring(11))) {
tongji++;
}中的星期五换成你想要查询的星期几
*/