scala 当前日期
Scala is a general-purpose programming language, which is majorly used for data manipulation. It has libraries and support for almost all different utilities that are important. One of the important things that are required while programming is real-time date and time status and Scala has a solution for that too. This tutorial on check current date and time in Scala walks you through the method to create Scala variables that hold date and time stamps.
Scala是通用编程语言,主要用于数据处理。 它具有库和对几乎所有重要的不同实用程序的支持。 编程时所需的重要内容之一是实时日期和时间状态 ,Scala也提供了解决方案。 本教程介绍了如何在Scala中检查当前日期和时间,并逐步引导您创建包含日期和时间戳的Scala变量。
使用日历类获取Scala中的当前日期和时间 (Getting current Date and Time in Scala using calendar class)
Getting current date and time in Scala is very simple and you can do this using the classical java 'calendar' class.
在Scala中获取当前日期和时间非常简单,您可以使用经典的java'calendar'类来实现 。
This class can be imported using the statement: "java.util.Calendar". The calendar class in java is an abstract class that is used to get the current date and time. The same class is used in Scala too, we can get the current date and time using it. There is a field in this class that stores the current date and time.
可以使用以下语句导入此类: “ java.util.Calendar” 。 java中的calendar类是一个抽象类,用于获取当前日期和时间 。 Scala中也使用了相同的类,我们可以使用它来获取当前日期和时间 。 此类中的一个字段用于存储当前日期和时间 。
Program to get time using getInstance() method
程序使用getInstance()方法获取时间
import java.util.Calendar;
object MyClass {
def main(args: Array[String]) {
var dT = Calendar.getInstance()
var currentMinute = dT.get(Calendar.MINUTE)
var currentHour = dT.get(Calendar.HOUR_OF_DAY)
if(currentHour > 12){
currentHour %= 12
println("Current time is "+currentHour+":"+currentMinute+" PM")
}
else{