Android随时显示当前时间

        //直接在方法中打      
Calendar c = Calendar.getInstance(); // 获取当前年份 String mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前月份 String mMonth = String.valueOf(c.get(Calendar.MONTH) + 1); // 获取当前月份的日期号码 String mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH)); // 获取当前星期 他获得的是数字1 2 3 4 5 6所以根据数字换一下 String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK)); if ("1".equals(mWay)) { mWay = ""; } else if ("2".equals(mWay)) { mWay = ""; } else if ("3".equals(mWay)) { mWay = ""; } else if ("4".equals(mWay)) { mWay = ""; } else if ("5".equals(mWay)) { mWay = ""; } else if ("6".equals(mWay)) { mWay = ""; } else if ("7".equals(mWay)) { mWay = ""; }
//textview赋值 date.setText(mYear
+ "." + mMonth + "." + mDay + " 星期" + mWay+"              "+"今天");

效果:

posted @ 2016-03-16 21:20  无名“  阅读(284)  评论(0编辑  收藏  举报