当前位置:   article > 正文

android自动获取系统时间,Android--获取系统时间的几种方式

android system.currenttimemillis import

方式一:

import java.text.SimpleDateFormat;

SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss");

Date curDate = new Date(System.currentTimeMillis());

//获取当前时间String str = formatter.format(curDate);

方式二:

取得系统时间

1。

long time=System.currentTimeMillis();

2。

final Calendar mCalendar=Calendar.getInstance();

mCalendar.setTimeInMillis(time);

取得小时:mHour=mCalendar.get(Calendar.HOUR);

取得分钟:mMinuts=mCalendar.get(Calendar.MINUTE);

3。

Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料

t.setToNow(); // 取得系统时间。

int year = t.year;

int month = t.month;

int date = t.monthDay;

int hour = t.hour; // 0-23

4。

DateFormat df = new SimpleDateFormat("HH:mm:ss");

df.format(new Date());

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/808209
推荐阅读
相关标签
  

闽ICP备14008679号