Android Time Class

Get Old Month Using Time Class

// Author: Mahbub

/*
http://developer.android.com/reference/android/text/format/Time.html

just provide the month, year and day and get previous dates

Since Time class does not provides months and day name, you have to do that by yourself
*/

public void oldDate(int month, int year, int day) {
    
    --month;

    oldDay = 1; // here i did not vary the old months date

    String s;
    
    for (int i = 1; i <= 5; ++i) { // i am fetching last 5 month data
        
        if (month == -1) {
            month = 11;
            year = year - 1;
        }

        oldYear = year;
        oldMonth = month;
        
        Time old = new Time();
        old.set(oldDay, oldMonth, oldYear);
        s = "Month of "+old.month+ +old.year;
        
        // update
        --month;
    }
}



https://gist.github.com/lifeparticle/7139069

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s