How to convert String to date time in Scala?

Spread the love

Question Description

I am new to Scala and I’ve learned it for the last few days. I have a doubt about Scala’s date converting from string.

How to convert String to Date and time using Scala ?

Does it work the same way as Java?

When I do it that way, I get a compiler error and I can’t convert that into Scala because I am new to Scala. And I know that it’s not good to convert Java to Scala…

Please share your answer.

Practice As Follows

If you are using Java’s util.Date then like in java:

val format = new java.text.SimpleDateFormat("yyyy-MM-dd")

docs for formating – SimpleDateFormat

or if you are using joda’s DateTime, then call parse method:


docs – DateTime


Not what you're looking for? Browse other questions tagged

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.