scala 随机生成整数
In Scala programming language, there is an option for the programmer to use libraries of java because of its interoperability with java.
在Scala编程语言中,程序员可以选择使用Java库,因为它可以与Java互操作。
There are a few methods to extract the date of a program,
有几种方法可以提取程序的日期 ,
1)Java 8年 (1) Java 8 Year)
The java.time.year library is used to get the value of the current year.
java.time.year库用于获取当前年份的值 。
Syntax:
句法:
val data_int = Year.now.getvalue
Program:
程序:
import java.time.Year
object MyClass {
def main(args: Array[String]) {
val year: Int = Year.now.getValue;
printf(" "+year)
}
}
Output
输出量
2019
2)Java 8 localDate (2) Java 8 localDate )
The java.time.localDate library is used to get the current date and we can extract year also using its method.
java.time.localDate库用于获取当前日期 ,我们也可以使用其方法提取年份 。
Synatx:
Synatx:
val data_int = LocalDate.now.getvalue
Example:
例:
import java.time.LocalDate
object MyClass {
def main(args: Array[String]) {
val year: Int = LocalDate.now.getYear;
printf(" "+year)
}
}
Output
输出量
2019
3)Java日历 (3) Java Calendar)
The java.util.calendar is used to to get calendar information using the getInstance method. And passing the Calendar.YEAR to it will return the value of Year.
java.util.calendar用于使用getInstance方法获取日历信息 。 并将Calendar.YEAR传递给它将返回Year的值。
Synatx:
Synatx:
val year = Calendar.getInstance.get(Calendar.YEAR)
Example:
例:
import java.util.Calendar
object MyClass {
def main(args: Array[String]) {
val year: Int = Calendar.getInstance.get(Calendar.YEAR);
printf(" "+year)
}
}
Output
输出量
2019
翻译自: https://www.includehelp.com/scala/how-to-get-the-current-year-as-an-integer-in-scala.aspx
scala 随机生成整数