java中获取当月1号零时零分的时间

  1. /** 
  2.      * 获得当月1号零时零分零秒 
  3.      * @return 
  4.      */  
  5.     public Date initDateByMonth(){  
  6.         Calendar calendar = Calendar.getInstance();  
  7.         calendar.setTime(new Date());  
  8.         calendar.set(Calendar.DAY_OF_MONTH, 1);  
  9.         calendar.set(Calendar.HOUR_OF_DAY, 0);  
  10.         calendar.set(Calendar.MINUTE, 0);  
  11.         calendar.set(Calendar.SECOND, 0);  
  12.         return calendar.getTime();  
  13.     }
  14. 第二种 
  15. import java.text.SimpleDateFormat;
  16. import java.util.Calendar;
  17. import java.util.Date;
  18. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
  19. Calendar cale = null;  
  20. cale = Calendar.getInstance();  
  21. cale.add(Calendar.MONTH, 0);  
  22. cale.set(Calendar.DAY_OF_MONTH, 1);  
  23. String  firstday = format.format(cale.getTime());  

猜你喜欢

转载自blog.csdn.net/qq_21101587/article/details/79351645
今日推荐