当前位置: 首页 > 工具软件 > Mia-Studio > 使用案例 >

android studio调出来,Android studio获取系统日期 并设置显示出来

单琛
2023-12-01

Calendar calendar = Calendar.getInstance();

mMonth = String.valueOf(calendar.get(Calendar.MONTH) + 1); //获取日期的月

mDay = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)); //获取日期的天

mWay = String.valueOf(calendar.get(Calendar.DAY_OF_WEEK)); //获取日期的星期

/**

* 如果小时是个位数

*

*则在前面价格“0”

* */

if (calendar.get(Calendar.HOUR) < 10) {

mHours = "0" + calendar.get(Calendar.HOUR);

} else {

mHours = String.valueOf(calendar.get(Calendar.HOUR));

}

/**

* 如果分钟是个位数

*

*则在前面价格“0”

* */

if (calendar.get(Calendar.MINUTE) < 10) {

mMinute = "0" + calendar.get(Calendar.MINUTE);

} else {

mMinute = String.valueOf(calendar.get(Calendar.MINUTE));

}

/**

* 获取星期

* 并设置出来

* */

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 = "六";

}

 类似资料: