Creating a dateRange Scala, Joda, Java

后端 未结 5 547
生来不讨喜
生来不讨喜 2020-12-16 01:34

I have spent hours trying to make this next piece of code work.

import org.joda.time.{DateTime, Period}


def dateR         


        
5条回答
  •  鱼传尺愫
    2020-12-16 02:06

    DateTime doesn't have a constructor taking three int arguments, so new DateTime(2012, 06, 30) calls DateTime(Object) constructor with the tuple (2012, 06, 30) as the argument. The documentation says:

    Constructs an instance from an Object that represents a datetime.

    If the object implies a chronology (such as GregorianCalendar does), then that chronology will be used. Otherwise, ISO default is used. Thus if a GregorianCalendar is passed in, the chronology used will be GJ, but if a Date is passed in the chronology will be ISO.

    The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date. The String formats are described by ISODateTimeFormat.dateTimeParser().

    Unsurprisingly, ConverterManager doesn't know what to do with a Scala tuple, which results in the exception.

    If someone can give me a different solution, that would also be great. I want a list of dates from 2000 to 2012, every 6 months.

    If you actually want dates, the better type to use is LocalDate (which does have the constructor you want, by the way). If you want DateTime at the start of these dates, then you need to think about what time zone to use.

提交回复
热议问题