package com.huawei.datetest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
public class DateTest {
public static void sortStringArray(int[] arrStr) {
int temp;
for (int i = 0; i < arrStr.length; i++) {
for (int j = arrStr.length - 1; j > i; j--) {
if (arrStr[i] > arrStr[j]) {
temp = arrStr[i];
arrStr[i] = arrStr[j];
arrStr[j] = temp;
}
}
}
}
public void getDateStr2(String [] dataString,String dateStr ) throws ParseException{
int[] result=new int[dataString.length+1];
int dataResult=Integer.parseInt(dateStr);
for(int i=0;i<dataString.length-1;i++){
result[i]=Integer.parseInt(dataString[i]);
}
result[dataString.length]=dataResult;
sortStringArray(result);
for(int i=0;i<result.length-1;i++){
System.out.println(result[i]);
if(result[i]==dataResult){
System.out.println("向前最近的日期为:"+result[i-1]);
System.out.println("向后最近的日期为:"+result[i+1]);
}
}
}
public static void main(String args[]) throws ParseException{
DateTest t1=new DateTest();
String dataStrings[] = new String[7];
dataStrings[0] ="20130806";
dataStrings[1] ="20130810";
dataStrings[2] ="20130816";
dataStrings[3] ="20130825";
dataStrings[4] ="20130828";
dataStrings[5] ="20130826";
String dateStr="20130819";
t1.getDateStr2(dataStrings, dateStr);
}
}