package com.logtech;
import com.logtech.Util.CalendarUtil;
import lombok.extern.slf4j.Slf4j;
import sun.util.calendar.CalendarUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* @author Loggyf
* @version 1.0
* @date 2018/12/27 12:15
*/
@Slf4j
public class CalendarTest {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("YYYY_MM_dd HH:mm:ss");
Calendar start = CalendarUtil.getTodayStartMoment();
Calendar end = CalendarUtil.getTodayEndMoment();
Calendar now = Calendar.getInstance();
Calendar start1 = CalendarUtil.getTodayStartMoment(now);
Calendar end1 = CalendarUtil.getTodayEndMoment(now);
Calendar start2 = CalendarUtil.getTodayStartMoment(Calendar.getInstance());
Calendar end2 = CalendarUtil.getTodayEndMoment(Calendar.getInstance());
log.info("start : {}",start.getTime());
log.info("end : {}",end.getTime());
System.out.println("------------------------");
log.info("start1 : {}",start1.getTime());
log.info("end1 : {}",end1.getTime());
System.out.println("------------------------");
log.info("start2 : {}",start2.getTime());
log.info("end2 : {}",end2.getTime());
}
}
package com.logtech.Util;
import java.util.Calendar;
/**
* @author Loggyf
* @version 1.0
* @date 2018/12/27 12:06
*/
public class CalendarUtil {
public static Calendar getTodayStartMoment(){
Calendar now = Calendar.getInstance();
return getTodayStartMoment(now);
}
public static Calendar getTodayEndMoment(){
Calendar now = Calendar.getInstance();
return getTodayEndMoment(now);
}
public static Calendar getTodayStartMoment(Calendar calendar){
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
return calendar;
}
public static Calendar getTodayEndMoment(Calendar calendar){
calendar.set(Calendar.HOUR_OF_DAY,23);
calendar.set(Calendar.MINUTE,59);
calendar.set(Calendar.SECOND,59);
calendar.set(Calendar.MILLISECOND,999);
return calendar;
}
}
?????Calendar问题,求解,错在哪里??
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...