How to use nscala-time parsing string with specific format

I find this time library for Scala, it is the cover of Joda Time. But I cannot find a way to parse String objects to DateTime using this library.

import com.github.nscala_time.time.Imports._


After importing this library, DateTime does not have a method parse

that takes a Date string and a specific DateTimeFormatter as arguments and returns a DateTime object.


source to share

1 answer

import com.github.nscala_time.time.Imports._

use 'DataTime' as an alias before ' StaticDateTime .
Therefore, you can do one of the following:

  • use DateTimeFormat . eg:DateTimeFormat.forPattern("DD:HH").parseDateTime("11:22")

  • import org.joda.time.DateTime after importing nscala_time (and lose StaticDateTime)

  • use the full name: org.joda.time.DateTime.parse(...)

  • import one of them with a different name:

    import com.github.nscala_time.time.Imports._
    import org.joda.time.{DateTime=>JodaDateTime}



All Articles