0

I am trying to cast com.github.nscala_time.time.Imports.DateTime from nscala-time (a wrapper of joda-time) to java.util.Date

activeUntil.toDate()

But I get this error

value toDate is not a member of Option[com.github.nscala_time.time.Imports.DateTime]

Obviuosly is not the right way to do it. Is there a way to do this?

Thank you in advance

1 Answer 1

2

Apparently activeUntil is an Option[DateTime] not DateTime itself. You can map it to Date and get providing some default value in case Option is empty like this

activeUntil.map(_.toDate).getOrElse(new Date())

I am not sure where did you get activeUntil from, but probably from a method that can fail to give you your DateTime this is why it returned an Option and forced you to handle the case when there is nothing to return.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.