android 获取时间

来源:互联网 发布:wait await java 编辑:程序博客网 时间:2024/06/18 09:10

第一种是具体的时候,如:2012-12-2-18:00:56 这种的我管它叫绝对时间:

        Date date_sys =  new Date(System.currentTimeMillis());// dd MM yyyy HH:mm:ss  日 月 年 小时 分 秒 注意大小写 MMM  --> "xx月"SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");CharSequence time = dateFormat.format(date_sys);

        第二种是相对的时间,如: 昨天:

                  int flags = DateUtils.FORMAT_ABBREV_RELATIVE;                  CharSequence time = (DateUtils.getRelativeTimeSpanString(date,                  System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags));