Add Calendar's field to Bundle - Android Android OS

Android examples for Android OS:Bundle

Description

Add Calendar's field to Bundle

Demo Code


//package com.java2s;

import java.util.Calendar;

import java.util.Locale;
import android.os.Bundle;

public class Main {
    public static Bundle bundleCalendar(Calendar cal) {
        Bundle args = new Bundle();
        if (cal == null)
            cal = Calendar.getInstance(Locale.getDefault());
        ;// w w w.  j  a v a 2 s. com
        args.putInt("year", cal.get(Calendar.YEAR));
        args.putInt("month", cal.get(Calendar.MONTH));
        args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
        args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
        args.putInt("minute", cal.get(Calendar.MINUTE));
        return args;
    }

    public static Bundle bundleCalendar(Calendar cal, long minDate) {
        Bundle args = new Bundle();
        if (cal == null)
            cal = Calendar.getInstance(Locale.getDefault());
        ;
        args.putInt("year", cal.get(Calendar.YEAR));
        args.putInt("month", cal.get(Calendar.MONTH));
        args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
        args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
        args.putInt("minute", cal.get(Calendar.MINUTE));
        args.putLong("minDate", minDate);
        return args;
    }
}

Related Tutorials