2015-05-01 49 views
0

据乔达文档:与LOCALDATE构造约达说构造LOCALDATE的(INT,INT,INT)是不可见的

public LocalDate(int year, 
    int monthOfYear, 
    int dayOfMonth, 
    Chronology chronology) 

应该采取上述我做到了。我试图年表设置为空,但我得到了以下错误:

The constructor LocalDate(int, int, int, null) is undefined 

但是我传递正确的价值观,但是从我的理解年表null表示ISOChronology在默认时区。

因此,如何传递三个正确的整数值并正确使用构造函数?

if (cit.hasNext()) { 
        cell = cit.next(); 
        cell.setCellType(Cell.CELL_TYPE_NUMERIC); 

        if (DateUtil.isCellDateFormatted(cell)) 
        { 
         SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); 
         String cellValue = sdf.format(cell.getDateCellValue()); 

         //System.out.println(cellValue); 

         //bufferDate is getting mm/dd/yyyy from excel cell 
         String[] dateSpliter = cellValue.split("/"); 
         int month= Integer.parseInt(dateSpliter[0]); 
         int day= Integer.parseInt(dateSpliter[1]); 
         int year= Integer.parseInt(dateSpliter[2]); 

         _date = new LocalDate(year,month,day,null); 

         po.setDate(_date);    
        } 
+2

乔达什么版本? –

+0

Dave的问题很重要,但我也注意到您创建LocalDate的逻辑有多复杂。为什么不使用LocalDate.fromDateFields(cell.getDateCellCalue())(请参阅:http://joda-time.sourceforge.net/apidocs/org/joda/time/LocalDate.html#fromDateFields(java.util.Date))这种复杂的逻辑涉及非常缓慢和大SimpleDateFormat? –

+0

您的标题与您的问题文字不符。你能解决这个问题吗? – Tom

回答

3

它在我看来就像是你输入了错误的类。

Java 8 java.time.LocalDate类没有公共构造函数,但它确实有一个私有构造函数,它需要三个int值。我认为这个类是你误导入的,当你想要org.joda.time.LocalDate。

相关问题