Android-day date conversion Sunday period

Source: Internet
Author: User
Tags locale

function function: Day date conversion Sunday period
Input data:
String: Date Yyyy-mm-dd.
Integer: Number of steps.
Output data:
int[]: Number of steps (7 days, Sunday to Saturday), final uniform (0-100) value, null-1 padding.
ArrayList<Pair<String, String>>: [Week, date number] (7 days, Sunday to Saturday), empty arrays are populated with [NULL,-1].

    /** * Convert Day Data * Input is an array of [date, data], converted to 7-day data combination, missing days are null-padded, default from Sunday to Monday, * weekly from Sunday to Monday [7 Day Data (1000), 7 day description (Sunday, Mon 1 2)]. * * @param DS Data * 7 Day Data converted @return  */    Privatearraylist<pair<int[], arraylist<pair<string, string>>>>Todaydata(Arraylist<pair<string, integer>> DS) {arraylist<pair<int[], arraylist<pair<string, string>>>> result =NewArraylist<> (); arraylist<string> dates =NewArraylist<> ();//Date arrayarraylist<integer> steps =NewArraylist<> ();//number of steps array         for(inti =0; I < ds.size ();            ++i) {Dates.add (Ds.get (i). first);        Steps.add (Ds.get (i). second); } arraylist<integer> Suns = Getsunarray (dates);//Get Sunday dataarraylist<arraylist<pair<string, string>>> alldates =NewArraylist<> ();//7 day week date formatarraylist<int[]> allsteps =NewArraylist<> ();//7 days/week steps        //Weekly data record         for(inti =0; I < suns.size (); ++i) {arraylist<pair<string, string>> weekdates =NewArraylist<> ();int[] Weeksteps =New int[7];intSunno = Suns.get (i);//Sunday serial number             for(intj =0; J <7; J + +) {intno = Sunno-j;if(No >=0) {pair<string, string> PS = Getweekwithno (Dates.get (no));                    Weekdates.add (PS);                WEEKSTEPS[J] = Steps.get (no); }Else{//Blank datapair<string, string> PS = pair.create ("NULL","-1");                    Weekdates.add (PS); WEEKSTEPS[J] =-1; }            }//Mean value            intmax = Getmaxvalue (weeksteps);if(max = =0) {max =1; } for(intj =0; J < Weeksteps.length; ++J) {Weeksteps[j] = weeksteps[j] * -/MAX;            } alldates.add (Weekdates);        Allsteps.add (weeksteps); }//remaining date record, which is not included in the weekly data Sunday        if(Suns.get (Suns.size ()-1) < (Ds.size ()-1) {arraylist<pair<string, string>> weekdates =NewArraylist<> ();int[] Weeksteps =New int[7];intElweekno = Suns.get (Suns.size ()-1) +7; for(intj =0; J <7; J + +) {intno = Elweekno-j;if(No <= (ds.size)-1) {pair<string, string> PS = Getweekwithno (Dates.get (no));                    Weekdates.add (PS);                WEEKSTEPS[J] = Steps.get (no); }Else{//Blank datapair<string, string> PS = pair.create ("NULL","-1");                    Weekdates.add (PS); WEEKSTEPS[J] =-1; }            }//Mean value            intmax = Getmaxvalue (weeksteps); for(intj =0; J < Weeksteps.length; ++J) {Weeksteps[j] = weeksteps[j] * -/MAX;            } alldates.add (Weekdates);        Allsteps.add (weeksteps); }//Final data form         for(inti = alldates.size ()-1; I >=0;        -i) {Result.add (Pair.create (Allsteps.get (i), alldates.get (i))); }returnResult }/** * Maximum value * * @param Array array * @return Maximum */    Private Static int Getmaxvalue(int[] array) {intMaxValue = array[0]; for(inti =1; i < Array.Length; i++) {if(Array[i] > MaxValue)            {maxValue = Array[i]; }        }returnMaxValue; }/** * Date data found Sunday location * * @param days Date list * @return Sunday Position array */    PrivateArraylist<integer>Getsunarray(Arraylist<string> days) {SimpleDateFormat SDF =NewSimpleDateFormat ("EEE", locale.english); Arraylist<integer> Posarray =NewArraylist<> (); for(inti =0; I < days.size ();            ++i) {Date date = Mdatemanager.getdatefromstr (Days.get (i)); String weekday = Sdf.format (date);if(Weekday.equals ("Sun") {Posarray.add (i); }        }returnPosarray; }/** * Convert date string to [week statement, date number] * * @param Day date * @return [Week statement, date number] */    PrivatePair<string, string>Getweekwithno(String Day)        {Date date = Mdatemanager.getdatefromstr (day); SimpleDateFormat SDF =NewSimpleDateFormat ("EEE", locale.english);        String weekday = Sdf.format (date);        Calendar calendar = Calendar.getinstance ();        Calendar.settime (date); String no = Calendar.get (calendar.day_of_month) +"";returnPair.create (Weekday, no); }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android-day date conversion Sunday period

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.