Android获取当前时间与星期几
Posted 星辰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android获取当前时间与星期几相关的知识,希望对你有一定的参考价值。
public class DataString { private static String mYear; private static String mMonth; private static String mDay; private static String mWay; public static String StringData(){ final Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份 mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份 mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码 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 ="六"; } return mYear + "年" + mMonth + "月" + mDay+"日"+"/星期"+mWay; } }
以上是关于Android获取当前时间与星期几的主要内容,如果未能解决你的问题,请参考以下文章