日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

scala 随机生成整数_如何在Scala中以整数形式获取当前年份?

發(fā)布時(shí)間:2023/12/1 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala 随机生成整数_如何在Scala中以整数形式获取当前年份? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

scala 隨機(jī)生成整數(shù)

In Scala programming language, there is an option for the programmer to use libraries of java because of its interoperability with java.

在Scala編程語言中,程序員可以選擇使用Java庫,因?yàn)樗梢耘cJava互操作。

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庫用于獲取當(dāng)前年份的值 。

Syntax:

句法:

val data_int = Year.now.getvalue

Program:

程序:

import java.time.Yearobject 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庫用于獲取當(dāng)前日期 ,我們也可以使用其方法提取年份 。

Synatx:

Synatx:

val data_int = LocalDate.now.getvalue

Example:

例:

import java.time.LocalDateobject 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.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 隨機(jī)生成整數(shù)

總結(jié)

以上是生活随笔為你收集整理的scala 随机生成整数_如何在Scala中以整数形式获取当前年份?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。