First introduce two auxiliary classes.

xiaoxiao2021-03-06  67

Package Webkiosk.Util;

/ **

* @Author jeff.qian

* Created on 2004-8-4

* /

Public Final Class ArrayUtil {

/ *

* Split strings into string arrays

* For example "AB, AC, AD, BC" -> {"ab", "ac", "ad", "bc"}

* Divison - separator

* * /

Public static string [] StringToArray (String S, String Division)

{

IF (s == null || s.LENGTH () == 0) Return New String [0];

String [] TempValue = New String [GetLength (S, Division];

INT count = 0;

While (S.indexof (Division)! = - 1) {

TempValue [count] = s.substring (0, sindexof (division));

s = s.substring (S.Indexof (Division) 1, S.Length ());

COUNT ;

}

IF (sindexof (division) == - 1) {

TempValue [count] = S;

}

Return Tempvalue;

}

/ *

* Segment strings into an INT array

* For example: "12, 34, 56, 78" -> {12, 34, 56, 78}

* /

Public Static Int [] INTTOARRY (String S, String Division)

{

IF (s == null || s.LENGTH () == 0) Return New Int Int [0];

Int [] Tempvalue = New INT [GetLength (S, Division)];

INT count = 0;

While (S.indexof (Division)! = - 1) {

TempValue [count] = integer.parseint (s.substring (0, sindexof (division)));

s = s.substring (S.Indexof (Division) 1, S.Length ());

COUNT ;

}

IF (sindexof (division) == - 1) {

TempValue [count] = integer.parseint (s);

COUNT ;

}

Return Tempvalue;

}

/ *

* Generate the length of the array

* * /

Public Static Int getLength (String in, string division) {

IF (in == null || in.LENGTH () == 0) Return 0;

Char [] temp = in.tochararray ();

INT count = 1;

For (int i = 0; i

IF (String.Valueof (Temp [I]). Equalsignorecase (Division)) Count ;

}

Return count;

}

Public static string arraytostring (String [] args, string division {

StringBuffer SB = New StringBuffer (512); for (int i = 0; i

Sb.append (args [i]);

IF (i! = (args.length-1)) sb.append (division);

}

Return sb.toString ();

}

Public Static String ArrayTString (int [] args, string division {

StringBuffer SB = New StringBuffer (512);

For (int i = 0; i

Sb.append (args [i]);

IF (i! = (args.length-1)) sb.append (division);

}

Return sb.toString ();

}

}

/ * * Create a date 2004-10-27 * @Author jeff.qian * @ves 0 1.0 * / package webkiosk.util;

Import java.text.parsexception; import java.text.SIMPLEDATEFORMAT; import java.util.arrayList; import java.util.date; import java.util.calendar; import java.util.gregoriancalendar;

/ ** * @Author jeff.qian * Transformation between use and characters * / public final class dateinterval {

// Define the date format // Enter private string inputformat = "YYYY-MM-DD"; // Output Private string OutputFormat = "YYYY-MM-DD"; / ** * @Param INPUTFORMAT To set the inputFormat to set. * / Public void setInputFormat (String InputFormat) {this.inputformat = inputformat;} / ** * @Param OutputFormat To set OutputFormat.

* / Public void setOutputFormat (String outputFormat) {this.outputFormat = outputFormat;} public DateInterval () {} public DateInterval (String inputFormat, String outputFormat) {this.inputFormat = inputFormat; this.outputFormat = outputFormat;} public Date formatString ( String Source) {// First Judgment Format SimpleDateFormat DF = New SimpleDateFormat (InputFormat); // DF.setlenient (false); Date Date = NULL; TRY {Date = DF.PARSE (Source);} catch (parseException PE) { PE.PrintStackTrace (); DATE = New Date ();} returnate;} / ** * The time interval between the returns, such as: * 2004-10-8 - 2004-10-10, if the sky is The interval, returns * {"2004-10-8", "2004-10-9", "2004-10-10"} * Flag default value * -1: Indicates the hour calculation * 0: Represents Day (DAY) * 1: Representing Week * 2: Month * 3: Representation Quarter * 4: Represents Year (Year) * * / public arraylist getIntervals (Date Begin, Date End, Int F LAG) {ArrayList List = New ArrayList (); Calendar Cal1 = New GregorianCalendar (); Cal1.SetTime (Begin); Calendar Cal2 = New Gregoriancalendar (); Cal2.SetTime (End); Cal2.add (Calendar.day_of_year, 1 Cal1.clear (Calendar.MilliseCond); Cal1.clear (Calendar.Second); Cal1.clear (Calendar.minute); Cal1.clear (Calendar.Hour_Of_DAY); SimpleDateFormat DF = New SimpleDateFormat (OutputFormat); Date Date = NULL; // Handling IF (FLAG == 0) {if ((! Cal1.before (CAL2) &&

(! Cal1.After (CAL2)))))) {list.add (begin)); List.add (DF.Format (end));} else {while (! Cal1.After (CAL2)) { Date = CAL1.GETTIME (); list.add (df.format (date)); Cal1.add (Calendar.day_of_year, 1);}}} // Processing IF incremented by weeks (FLAG == 1) {INT first = CAL1.GET (Calendar.day_of_week; list.add (df.format ()); Cal1.add (Calendar.day_of_year, (8-first)); while (Cal1.before " Cal2)) {date = CAL1.GETTIME (); list.add (df.format (date)); Cal1.add (Calendar.day_of_year, 7);} if (! Cal1.before (CAL2)) {Date = CAL2 .get.add (DF.Format (Date));}} // Processing the IF incremented by month-oriented unit (FLAG == 2) {DATE = Cal1.getTime (); list .add (DF. Format (date); Cal1.clear (Calendar.da) Y_of_month); Cal1.add (Calendar.month, 1); While (Cal1.before (CAL2)) {date = CAL1.GETTIME (); list.add (df.format (date)); Cal1.Add (Calendar. Month, 1);} if (! Cal1.before (CAL2)) {date = cal2.gettime (); list.add (df.format (date));}} // Processing in quarterly incremented IF ( Flag == 3) {date = CAL1.GETTIME (); list.add (df.format (date)); cal1.day_of_month; int first = CAL1.GET (Calendar.Mont); Cal1.Add (Calendar.Month, (4- (FigSt 1)% 3));

While (Cal1.before (CAL2)) {date = CAL1.GETTIME (); list .add (df.format (date)); Cal1.add (Calendar.Month, 3);} if (! Cal1.before (CAL2) )) {Date = CAL2.GETTIME (); list.add (df.format (date));}} // Processing IF incremented by year (FLAG == 4) {date = CAL1.GETTIME (); List.add (DFMAT (DATE)); Cal1.Day_OF_MONTH); Cal1.clear (Calendar.mont); Cal1.Add (Calendar.Year, 1); While (Cal1.before (CAL2)) {DATE = CAL1.GETTIME (); list.add (DF.Format (Date)); Cal1.Add (Calendar.Year, 1);} if (! Cal1.before (CAL2)) {date = cal2.gettime ); List.add (DFMAT (DATE));}} // Handling IF in hours (FLAG == - 1 && (DF.Format (begin))))) {SimpleDateFormat DF2 = New Simpled Ateformat ("YYYY-MM-DD HH: MM: SS"); List.Add (Df2.Format ())); for (int K = 0; k <24; k ) {Cal1.Add ( Calendar.Hour_of_day, 1); list.add (df2.format ());}} Return List;}}}}}}}}}}}}}}}} {DateInterval du = new dateInterval (); Date Date1 = du.formatString ("2004-11-11"); Date Date2 = du.FormatString ("2004-11-11"); arraylist list = du.getIntervals (date1, date2, 0); int count = 0; while (count <

转载请注明原文地址:https://www.9cbs.com/read-89726.html

New Post(0)