一年的第多少周+一个月的第多少天+一周的第多少天

package cn.mybatis.dao.impl;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName TimeTest
 * @Description TODO
 * @Author 张大仙
 * @Date 2020/6/24  18:03
 * @Version 1.0
 **/


public class TimeTest {
     

    @Test
    public void javaTime() throws ParseException {
     
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        Date date = format.parse("2020-05-18");
//        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); //一年的多少周
        int dataMonthDay = calendar.get(Calendar.DAY_OF_MONTH); //一个月的第多少天
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //一周的第几天
        //返回值为1的话  为周日
        //返回值为7的话  为周六
        if (dayOfWeek==1){
     
            dayOfWeek = 7;
        }else {
     
            dayOfWeek = dayOfWeek - 1;
        }

        System.out.println("一年的第多少周:" + weekOfYear);
        System.out.println("一个月的第多少天:" + dataMonthDay);
        System.out.println("一周的第多少天:" + dayOfWeek);

    }
}

你可能感兴趣的:(日常-通用类,java)