计算距离下一个生日还有多少天:

 public void getBirthday() {        String birthday = "2013-03-18";        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");        Calendar cal = Calendar.getInstance();        int yearNow = cal.get(Calendar.YEAR);// 获得当前年份        try {            Log.i("Birthday_time", formatter.parse(birthday) + "");            cal.setTime(formatter.parse(birthday));        } catch (Exception e) {            e.printStackTrace();        }        int birthyear = cal.get(Calendar.YEAR);        Log.i("Birthday_year", birthyear + "");        while (birthyear < yearNow) {            cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);            birthyear = cal.get(Calendar.YEAR);            Log.i("Birthday_year++", birthyear + "");        }        Date ed = new Date();        Log.i("Date_ed", ed + "");        Date sd = cal.getTime();        Log.i("Date_sd", ed + "");        long days = 0;        if ((ed.getTime() - sd.getTime()) / (3600 * 24 * 1000) < 0) {//>            days = -((ed.getTime() - sd.getTime()) / (3600 * 24 * 1000)) + 1;            System.out.println("距离你生日还有" + days + "天");        } else {            cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);            sd = cal.getTime();            days = -((ed.getTime() - sd.getTime()) / (3600 * 24 * 1000)) + 1;            System.out.println("距离你生日还有" + days + "天");        }    }
调用上述方法即可得到距离下一个生日还需多少天。

更多相关文章

  1. android webview 中网页数据与js交互
  2. Android(安卓)GPS坐标距离计算
  3. 记事本。 layout相关
  4. 简单总结RectF、Rect 和Matrix ,还有Paint的使用方法
  5. 简单总结RectF、Rect 和Matrix ,还有Paint的使用方法
  6. android控件常用属性区别
  7. android listview 自定义分割线总结
  8. Android图形层叠 – Layer-list
  9. 安卓ListView去除分割线、设置边距

随机推荐

  1. Android so库编译错误 java.lang.Unsatis
  2. Android UTC和Local 时间互转
  3. Android 3D 旋转的三角形(二)
  4. Android中ListView的使用及优化
  5. Android Imageview图片旋转和大小变化
  6. This Handler class should be static or
  7. Android怎么让toast在屏幕顶部显示
  8. vitamio for android的使用
  9. android 获取包名 通过包名获取应用签名
  10. Android(安卓)不使用布局文件,动态地生产