get Day OF Year - Android java.util

Android examples for java.util:Year

Description

get Day OF Year

Demo Code

import android.text.TextUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main{
    public static final SimpleDateFormat yearFormat = new SimpleDateFormat(
            "yyyy-MM-dd");
    public static int getDayOFYear(String date) {
        try {//from   w  w  w.  j a va2  s .  com
            Date parse = yearFormat.parse(date);
            Calendar instance = Calendar.getInstance();
            instance.setTime(parse);
            return instance.get(Calendar.DAY_OF_YEAR);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

}

Related Tutorials