scala 当前日期_如何在Scala中检查当前日期和时间?

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{
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值