String in Scala
String is a collection of characters that is mutable, i.e. its contents cannot be modified.
Syntax for creating string:
val string_name : String = "string_value"
Example of string:
val string = "Includehelp"
Date in Scala
Date is a variable that stores the date-time information for the date. It uses the Calendar class present in java calendar library imported using import java.util.calendar.
Convert string to date in Scala
As Scala uses the java-based date library we can use methods in java to convert string to date. So, here we will use the parse method.
Syntax to convert a string to date using parse method:
val date = date_format_name.parse(string)
Program to convert string to date
Output:
Explanation:
Here, we have converted the string to date in Scala. For this, we have used the parse method in simpleDateFormat. After conversion, we have printed the date using the println statement.
need an explanation for this answer? contact us directly to get an explanation for this answer