如何获取当前的Andr​​oid设备上的时间? [英] How to get the time on the current android device?

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

问题描述

我想获得当前时间安装了应用程序在Android设备上。

I would like to get the current time on the android device with the app installed.

我希望能够做这样的事。

I want to be able to do something like this..

if(//time is pass noon){

//Do something


}
else{
//do something.
}

我要告诉如果它的上午或下午。

i want to tell if its am or pm.

推荐答案

下面是一个例子,应该可以帮助您:

Here is an example that should help you:

Calendar today = Calendar.getInstance();
Calendar expireDate = Calendar.getInstance();

expireDate.set(2011, Calendar.AUGUST, 12);

if (today.compareTo(expireDate) == 0 || today.compareTo(expireDate) == 1)

{
// expired - please purchase app

}
else
{
// do some stuff
}

要判断它是上午还是下午使用:

To tell if it is AM or PM use:

int value = today.get(Calendar.AM_PM);

或者你可以只得到一小时:

Or you could just get the hour:

int hour = today.get(Calendar.HOUR);

然后把在if语句:

And then put that in an if statement:

if (hour > 12)
{

// do stuff

}
else
{
// do other stuff
}

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

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