joda使用

import java.util.Date;

import org.joda.time.DateTime;

public class DateTest {

    public static void main(String[] args) {
        // 获取当前周的周一和周末
        System.out.println(String.format("min:%s, max:%s",
                DateTime.now().dayOfWeek().withMinimumValue()
                        .toString("yyyy-MM-dd"),
                DateTime.now().dayOfWeek().withMaximumValue()
                        .toString("yyyy-MM-dd")));

        DateTime dateTime = new DateTime(new Date());
        System.out.println(String.format("min:%s, max:%s",
                dateTime.minusDays(4).dayOfWeek().withMinimumValue()
                        .toString("yyyy-MM-dd"),
                dateTime.minusDays(4).dayOfWeek().withMaximumValue()
                        .toString("yyyy-MM-dd")));

        // 当前月的第一天和最后一天
        System.out.println(String.format("min:%s, max:%s",
                DateTime.now().dayOfMonth().withMinimumValue()
                        .toString("yyyy-MM-dd"),
                DateTime.now().dayOfMonth().withMaximumValue()
                        .toString("yyyy-MM-dd")));

    }
}

https://blog.csdn.net/zdc524/article/details/53215461

猜你喜欢

转载自www.cnblogs.com/6xiong/p/10873239.html
0条评论
添加一条新回复
  
今日推荐