Android Calendar Format formatReminder(Context ctx, Calendar date)

Here you can find the source of formatReminder(Context ctx, Calendar date)

Description

format Reminder

License

Open Source License

Declaration

public static CharSequence formatReminder(Context ctx, Calendar date) 

Method Source Code

/*******************************************************************************
 * Mirakel is an Android App for managing your ToDo-Lists
 * /*from   w  w w. j a va 2s  .  c  o m*/
 * Copyright (c) 2013-2014 Anatolij Zelenin, Georg Semmler.
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import android.content.Context;
import android.os.Build;
import android.text.format.DateUtils;
import android.text.format.Time;
import de.azapps.mirakelandroid.R;

public class Main{
    public static final SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyy-MM-dd", Locale.getDefault());
    public static CharSequence formatReminder(Context ctx, Calendar date) {
        return DateTimeHelper.formatDate(date,
                ctx.getString(R.string.humanDateTimeFormat));
    }
    public static String formatDate(Calendar c) {
        return c == null ? null : dateFormat.format(c.getTime());
    }
    
    public static CharSequence formatDate(Calendar date, String format) {
        if (date == null)
            return "";
        return new SimpleDateFormat(format, Locale.getDefault())
                .format(date.getTime());
    }
    
    public static CharSequence formatDate(Context ctx, Calendar date) {
        if (date == null)
            return "";
        if (MirakelPreferences.isDateFormatRelative()) {
            GregorianCalendar now = new GregorianCalendar();
            now.setTime(new Date());
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1
                    || !(now.get(Calendar.YEAR) == date.get(Calendar.YEAR)
                            && now.get(Calendar.DAY_OF_MONTH) == date
                                    .get(Calendar.DAY_OF_MONTH) && now
                            .get(Calendar.MONTH) == date
                            .get(Calendar.MONTH)))
                return DateUtils.getRelativeTimeSpanString(
                        date.getTimeInMillis(), new Date().getTime(),
                        DateUtils.DAY_IN_MILLIS);
            return ctx.getString(R.string.today);
        }
        return new SimpleDateFormat(ctx.getString(R.string.dateFormat),
                Locale.getDefault()).format(date.getTime());
    }
}

Related

  1. formatDBDateTime(Calendar c)
  2. formatDate(Calendar c)
  3. formatDate(Calendar date, String format)
  4. formatDate(Context ctx, Calendar date)
  5. formatDateTime(Calendar c)
  6. formatTM(Calendar c, StringBuffer sb)
  7. formatTaskWarrior(Calendar c)
  8. formateCalDav(Calendar c)
  9. formateCalDavDue(Calendar c)