scala 随机生成整数_如何在Scala中以整数形式获取当前年份?
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.getvalueProgram:
程序:
import java.time.Yearobject MyClass {def main(args: Array[String]) {val year: Int = Year.now.getValue; printf(" "+year)} }Output
輸出量
20192)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.getvalueExample:
例:
import java.time.LocalDateobject MyClass {def main(args: Array[String]) {val year: Int = LocalDate.now.getYear; printf(" "+year)} }Output
輸出量
20193)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.Calendarobject 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 隨機生成整數
總結
以上是生活随笔為你收集整理的scala 随机生成整数_如何在Scala中以整数形式获取当前年份?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 剑灵什么时候出枪手
- 下一篇: JavaScript中的String()