Android Date Format String Create dateFormatToString(int date, Context context)

Here you can find the source of dateFormatToString(int date, Context context)

Description

date Format To String

Declaration

public static String dateFormatToString(int date, Context context) 

Method Source Code

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import com.orange.R;
import android.content.Context;
import android.util.Log;

public class Main{
    public static String dateFormatToString(int date, Context context) {
        String dateString = "";
        long currentTime = System.currentTimeMillis() / 1000;
        int dateTime = (int) (currentTime - date) / 60;
        if (date == 0) {
            return dateString;
        }//from  w  w w  .  jav  a 2  s. c o m
        if (dateTime > 4320) {
            dateString = getDateString(date);
        } else if (dateTime > 1440 && dateTime < 4320) {
            dateString = dateTime / 1440
                    + context.getString(R.string.day_before);
        } else if (dateTime > 60 && dateTime < 1440) {
            dateString = dateTime / 60
                    + context.getString(R.string.hour_before);
        } else {
            dateString = (dateTime / 60 < 1 ? 1 : dateTime / 60)
                    + context.getString(R.string.minute_before);
        }
        return dateString;
    }
    public static String getDateString(long time) {
        Calendar date = Calendar.getInstance();
        time = time * 1000;
        //long targetTime = time - TimeZone.getDefault().getRawOffset();
        date.setTimeInMillis(time);

        SimpleDateFormat dateformat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm");
        String dateString = dateformat.format(date.getTime());
        return dateString;
    }
}

Related

  1. getFormat(String pattern)
  2. getDateFormatSymbols(Locale locale)
  3. changeFormat(String gmtString, String orgFormat, String format)
  4. convertFormat(String src, String f1, String f2)
  5. getGMTDateFormat()
  6. getSimpleDateFormat()
  7. getSimpleDateFormatter()
  8. getDateByFormat(String strDate, String format)