如何在Android中获取当前时间?
当我使用
int hours = java.sql.Time.this.getHours();
Run Code Online (Sandbox Code Playgroud)
我收到错误:
No enclosing instance of the type Time is accessible in scope
Run Code Online (Sandbox Code Playgroud) 我想在Android中获取当前时间.它应该显示为下午2:30,我想将其存储在数据库中.我搜索了很多.但我不知道该怎么做.我怎样才能做到这一点?
我想要得到约会.
我在日期和月份使用它
int date = cld.get(Calendar.DATE);
int month = cld.get(Calendar.MONTH);
Run Code Online (Sandbox Code Playgroud)
而不是它作为一个int返回我希望它是一个字符串.或者也许是完整的日期格式.
如:12/12/12或......
2011年8月14日
我该怎么做呢?
我试图让一个时间戳的时间,但我不断收到错误的时间,当我用Calendar.HOUR和Calendar.MINUTE,无论时间戳是它告诉我的时间是10分钟为12.
现在,当我使用Calendar.getTime()它给我正确的时间,所以我不明白?我只想以12小时格式和分钟获得小时
这是我如何去做
public static String getRealTime(long time){
Calendar cal = Calendar.getInstance();
Log.d("Calendar",String.valueOf(time));
cal.setTimeInMillis(time);
Date timeS = cal.getTime();
String sTime = timeS.toString(); // gives correct time in 24hr format
int hr = cal.HOUR; // gives me 10 no matter what the timestamp is
int min = cal.MINUTE; // gives me 12 no matter what the timestamp is
String dMin = getDoubleDigit(min);
int ampm = cal.AM_PM;
String m = new String();
if(ampm == 0){
m …Run Code Online (Sandbox Code Playgroud) 我一直在尝试为Android编写一个简单的数字时钟应用程序.首先,我使用内置的数字时钟,并试图省略秒显示,但我不能.我希望时钟的秒数可以触发我的一些代码行.
然后我开始开发简单的应用程序将Digits放在屏幕上,但我不知道如何以最有效的方式触发显示.任何人都可以给我一个简单的开始,在哪里看和使用什么功能?如何在每秒内执行几行代码?我尝试了在Android应用程序中显示当前时间和日期的示例但是没有成功.没有名为CountDownRunner的库可以导入.
我是Android开发的新手,但我在Java,C,C++方面有相当不错的经验.
谢谢
我需要格式化日期和时间格林威治标准时间2012年11月15日18:55.
时间应该是GMT和24小时格式.我尝试使用以下代码,但它以12小时格式给出时间.有什么办法吗?
DateFormat currentDateTimeString = DateFormat.getDateTimeInstance();
currentDateTimeString.setTimeZone(TimeZone.getTimeZone("gmt"));
gmtTime = currentDateTimeString.format(new Date());
Run Code Online (Sandbox Code Playgroud)