Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the java.time API in scala

Tags:

scala

I'm trying out Java 8 Date Time Api java.time using Scala REPL. Just encountered the problem below:

enter image description here

I do understand that the keyword with is reserved in scala, but also it is used in the API. Any idea on how to mitigate the limits?

like image 234
kmos.w Avatar asked Jan 28 '16 08:01

kmos.w


People also ask

What is Java time API?

Java Date-Time Packages. The Date-Time APIs, introduced in JDK 8, are a set of packages that model the most important aspects of date and time. The core classes in the java. time package use the calendar system defined in ISO-8601 (based on the Gregorian calendar system) as the default calendar.

How do you use dates in Scala?

So to use date in scala we can use java library by importing packages. After this we can use its function to deal with date and time in scala, we can parse, format, and create the date from string object as well.


1 Answers

Try wrapping the with with tick marks as follows:

val nextWed = today.`with`(java.time.temporal.TemporalAdjusters.next(DayOfWeek.WEDNESDAY))

Adding the ticks designates it a literal identifier.

like image 94
Al Iacovella Avatar answered Oct 14 '22 00:10

Al Iacovella