关闭

库存中货物超期的天数

标签: stringexceptiondateimportclass
732人阅读 评论(0) 收藏 举报

package stock;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import junit.framework.TestCase;

public class Test extends TestCase {
 
 private String monthfromdate;    //月初
 private String monthenddate;     //月末
 private long  periodday;  //周期
 private String indate;   //入库日期
 private String outdate;   //出库日期
 
 
 public Test(){}
 
 
 public Test(String monthfromdate, String monthenddate, long periodday, String indate, String outdate) {
  this.monthfromdate = monthfromdate;
  this.monthenddate = monthenddate;
  this.periodday = periodday;
  this.indate = indate;
  this.outdate = outdate;
 }

 public static long getCompareDate(String endDate,String startDate) throws ParseException{
      SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
     

      Date date1=formatter.parse(startDate);
      Date date2=formatter.parse(endDate);
     
      long l = date2.getTime() - date1.getTime();
      long d = l/(24*60*60*1000);
      return d;
  }
 
 // 1。在库存中货物超期的天数
 // 2。月末后出库的货物超期的天数
 //monthfromdate,monthenddate,indate
 public long compulatoverday1() throws ParseException{
  
  long monthdays =  getCompareDate(monthenddate,monthfromdate);
  long infromdays = getCompareDate(monthfromdate,indate);
  long inenddays = getCompareDate(monthenddate,indate);
  
  if( monthdays <= periodday){
   
   Exception exception = new Exception("没有超期");
   
   return -1;
  }
  
  if(infromdays>=periodday)
  {
   return monthdays;
  }else{
   return inenddays-periodday;
  }
  
 }
 
 
 //1。本月中出货货物超期的天数
 public long compulatoverday2() throws ParseException{
  
  long stockdays =  getCompareDate(outdate,indate);
  long monthdays =  getCompareDate(monthenddate,monthfromdate);
  long infromdays = getCompareDate(monthfromdate,indate);
  long outfromdays =  getCompareDate(outdate,monthfromdate);
  //long outenddays =  getCompareDate(monthenddate,outdate);

  
  System.out.println("本月共" + monthdays + "天");
  if( stockdays <= periodday){
   
   Exception exception = new Exception("没有超期");
   
   return -1;
  }
  
  if(infromdays>=periodday)
  {
   return outfromdays;
  }else{
   return stockdays-periodday;
  }
  
 }
 
 
 
 
 public static void main(String[] args) throws ParseException {
  
  Test test = new Test("2007-06-01","2007-07-01",7,"2007-05-08","2007-6-28");
  System.out.print(test.compulatoverday2());
  
//  System.out.print(getCompareDate("2007-06-01","2007-06-01"));
  
 }
 
 
 
 

 public String getIndate() {
  return indate;
 }

 public void setIndate(String indate) {
  this.indate = indate;
 }

 public String getMonthenddate() {
  return monthenddate;
 }

 public void setMonthenddate(String monthenddate) {
  this.monthenddate = monthenddate;
 }

 public String getMonthfromdate() {
  return monthfromdate;
 }

 public void setMonthfromdate(String monthfromdate) {
  this.monthfromdate = monthfromdate;
 }

 public String getOutdate() {
  return outdate;
 }

 public void setOutdate(String outdate) {
  this.outdate = outdate;
 }

 public long getPeriodday() {
  return periodday;
 }

 public void setPeriodday(long periodday) {
  this.periodday = periodday;
 }
 
 
 
 

}
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:106081次
    • 积分:1954
    • 等级:
    • 排名:千里之外
    • 原创:84篇
    • 转载:0篇
    • 译文:0篇
    • 评论:25条
    文章分类
    最新评论