Date nowDate= new Date();
//java DATE TO joda time
new DateTime(nowDate);
//今天是一個月裡的第幾天
new DateTime(nowDate).getDayOfMonth();
//這個月有幾天
new DateTime(nowDate).dayOfMonth().getMaximumValue();
//上個月有幾天
DateTime dayOfPeriousMonth = new DateTime(nowDate).minusMonths (1);
System.out.println(dayOfPeriousMonth);
int daysInPeriousMonth=dayOfPeriousMonth.dayOfMonth().getMaximumValue();
System.out.println(daysInPeriousMonth);
//取出上個月的12號
DateTime periousM12=dayOfPeriousMonth.withDayOfMonth(12);
System.out.println(periousM12 );
//joda time to java Date
new DateTime().toDate();
//本月第一天
DateTime firstDayOfMonth = new DateTime().dayOfMonth().withMinimumValue();
//某個時間是否是在今天內
if( new DateTime( someDateTime).isAfter( DateTime.now().minusDays(1) )){
System.out.println(someDateTime+" is in 24 hours");
}else {
System.out.println("not in!");
}
沒有留言:
張貼留言