仅在 int 中显示和保存小时数 [英] Display and save only hours in int

查看:29
本文介绍了仅在 int 中显示和保存小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何只显示小时并使用 int 变量?我的意思是打印时间像下午 20:30:44,我只想存储小时,在 int 变量中意味着 20.怎么做?

How to display only hours and using int variable? I mean print time like 20:30:44 PM, I want to store only hours, mean 20 in int variable. how to do that?

谁能告诉我代码,谢谢?

Can anybody tell me the code if you know, thanks?

推荐答案

尝试使用 Calendar 的 get 方法如:

Try using Calendar's get method like:

 Calendar c = ..
 c.setTime(...);//if you have time in long coming from somewhere else
 int hour = c.get(Calendar.HOUR_OF_DAY);

这篇关于仅在 int 中显示和保存小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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