当前位置: 代码迷 >> Android >> 『後伏Android开发05』android开发java语言获得今天,明天,后天日期
  详细解决方案

『後伏Android开发05』android开发java语言获得今天,明天,后天日期

热度:34   发布时间:2016-05-01 11:16:17.0
『後起Android开发05』android开发java语言获得今天,明天,后天日期

需要做一个获得今天,明天,后天日期的需求,自己就码出来了,没什么技术含量,贴出来方便有此需求的童鞋。
转载请注明:http://blog.csdn.net/liu17ezlyy

// 添加大小月月份并将其转换为list,方便之后的判断		String[] months_big = { "1", "3", "5", "7", "8", "10", "12" };		String[] months_little = { "4", "6", "9", "11" };		list_big = Arrays.asList(months_big);		list_little = Arrays.asList(months_little);

//获得今天日期	private String getTodayData(){		Calendar calendar = Calendar.getInstance();		String year = calendar.get(Calendar.YEAR)+"";		String month = calendar.get(Calendar.MONTH)+1+"";		String day = calendar.get(Calendar.DATE)+"";				String data=year+"-"+month+"-"+day;		return data;	}

//获得明天日期	private String getTomoData(){		Calendar calendar = Calendar.getInstance();		int year = calendar.get(Calendar.YEAR);		int month = calendar.get(Calendar.MONTH)+1;		int day = calendar.get(Calendar.DATE);		if(day==30){			if (list_big.contains(String.valueOf(month))){				day=31;			}			if (list_little.contains(String.valueOf(month))){				day=1;				if(month==12){					year++;					month=1;				}else{					month++;				}							}		}else if(day==31){			day=1;			if(month==12){				year++;				month=1;			}else{				month++;			}					}else {			day++;		}		String data=year+"-"+month+"-"+day;		return data;	}

//获得后天日期	private String getTheDayData(){		Calendar calendar = Calendar.getInstance();		int year = calendar.get(Calendar.YEAR);		int month = calendar.get(Calendar.MONTH)+1;		int day = calendar.get(Calendar.DATE);		if(day==30){			if (list_big.contains(String.valueOf(month))){				day=1;				if(month==12){					year++;					month=1;				}else{					month++;				}			}			if (list_little.contains(String.valueOf(month))){				day=2;				if(month==12){					year++;					month=1;				}else{					month++;				}			}		}else if(day==31){			day=2;			if(month==12){				year++;				month=1;			}else{				month++;			}					}else {			day=day+2;		}		String data=year+"-"+month+"-"+day;		return data;	}



  相关解决方案