获取当前时间 [英] Getting Current time of day

查看:58
本文介绍了获取当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void getTime()
{
    Calendar calendar = Calendar.getInstance();
    calendar.getTime();
    this.minutes = calendar.MINUTE;
    this.hours= calendar.HOUR_OF_DAY;

}

鉴于此代码将变量分钟和小时设置为当前时间的整数值?似乎没有问题吗?

Given this code does the variable minutes and hours set to the current time in an integer value? it doesn't seem so is there something wrong?

推荐答案

尝试从日历实例的日历实例获取分钟和小时当天

Try this to get the Minutes, and Hour from the Calender instance of Current Day

this.minutes = calendar.get(Calendar.MINUTE);
this.hours= calendar.get(Calendar.HOUR_OF_DAY);

Calendar.MINUTE Calendar.HOUR_OF_DAY 是常量,它仅提供int值。将int值应用于您的日历实例,并获取Minute和Hour值。

Calendar.MINUTE and Calendar.HOUR_OF_DAY are constants, it only give the int value. Apply the int value to your calendar instance and get the Minute and Hour value.

这篇关于获取当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆