DateUtils.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.kingdee.shr.customer.gtiit.osf.util;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import com.kingdee.bos.BOSException;
  6. public class DateUtils {
  7. /**
  8. * 转换起始时间为00:00:00,结束时间为23:59:59
  9. * @param dateStr
  10. * @param isStart
  11. * @return
  12. * @throws BOSException
  13. */
  14. public static String formatDate(String dateStr,boolean isStart) throws BOSException{
  15. String formattedDate="";
  16. try{
  17. Date nowDate = new Date();
  18. if(!dateStr.contains(":")) {
  19. DateFormat df = new SimpleDateFormat("hh:mm:ss");
  20. dateStr=dateStr+" "+df.format(nowDate);
  21. }
  22. SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  23. Date date = inputFormat.parse(dateStr);
  24. SimpleDateFormat outputFormat=null;
  25. if(isStart){
  26. outputFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  27. }else {
  28. outputFormat = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
  29. }
  30. formattedDate = outputFormat.format(date);
  31. }catch (Exception e){
  32. throw new BOSException(e);
  33. }
  34. return formattedDate;
  35. }
  36. }