Example usage for android.text.format DateFormat format

List of usage examples for android.text.format DateFormat format

Introduction

In this page you can find the example usage for android.text.format DateFormat format.

Prototype

public static CharSequence format(CharSequence inFormat, Calendar inDate) 

Source Link

Document

Given a format string and a java.util.Calendar object, returns a CharSequence containing the requested date.

Usage

From source file:com.snappy.CameraCropActivity.java

public void startCamera() {
    // Check if camera exists
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
        finish();//from   w ww.  j a v  a  2  s .  co  m
    } else {
        try {
            long date = System.currentTimeMillis();
            String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg";
            _path = this.getExternalCacheDir() + "/" + filename;
            File file = new File(_path);
            //            File file = new File(getFileDir(getBaseContext()), filename);
            Uri outputFileUri = Uri.fromFile(file);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, CAMERA);
        } catch (Exception ex) {
            Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
            finish();
        }

    }
}

From source file:io.github.a1inani.sphygmo.activity.CardActivity.java

public String getLastReadingDate() throws ParseException {
    String lastStr = db.getLastReadingDate();

    if (lastStr.isEmpty()) {
        return "No entries have been made.";
    }/*ww w  .  jav  a 2 s .  c  o  m*/

    SimpleDateFormat formatter = new SimpleDateFormat("MMMM, d, yyyy HH:mm:ss");
    Date parsedDate = formatter.parse(lastStr);
    Calendar lastCal = Calendar.getInstance();
    lastCal.setTime(parsedDate);
    Calendar now = Calendar.getInstance();

    if (now.get(Calendar.DATE) == lastCal.get(Calendar.DATE)) {
        return "Your last entry was today";
    } else if (now.get(Calendar.DATE) - lastCal.get(Calendar.DATE) == 1) {
        return "Your last entry was yesterday";
    } else
        return "Your last entry was on " + DateFormat.format("MMMM, d, yyyy", lastCal).toString();
}

From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java

public static String formatTime(final Context context, Calendar c) {
    String format = get24HourMode(context) ? M24 : M12;
    return (c == null) ? "" : (String) DateFormat.format(format, c);
}

From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java

private static String formatDayAndTime(final Context context, Calendar c) {
    String format = get24HourMode(context) ? DM24 : DM12;
    return (c == null) ? "" : (String) DateFormat.format(format, c);
}

From source file:com.fabernovel.alertevoirie.MyIncidentsActivity.java

private void setAdapterForTab(final int tab) {

    try {//from  w  ww .  j  a  v a  2  s .  co  m
        // Log.d(Constants.PROJECT_TAG, data.getJSONArray(INCIDENTS[tab]).toString());

        setListAdapter(new JSONAdapter(this, data.getJSONArray(INCIDENTS[tab]), R.layout.cell_report_noicon,
                new String[] { JsonData.PARAM_INCIDENT_DESCRIPTION, JsonData.PARAM_INCIDENT_ADDRESS },
                new int[] { R.id.TextView_title, R.id.TextView_text }, null, JsonData.PARAM_INCIDENT_DATE,
                R.layout.cell_category) {
            @Override
            protected String getCategoryOfItem(int itemId) {
                String date = super.getCategoryOfItem(itemId).substring(0, 10);

                Log.d(Constants.PROJECT_TAG, date);

                return ((String) DateFormat.format("MMMM yyyy", new Date(Integer.parseInt(date.substring(0, 4)),
                        Integer.parseInt(date.substring(5, 7)) - 1, Integer.parseInt(date.substring(8, 10)))))
                                .replace("39", "20");
                // return date;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = super.getView(position, convertView, parent);
                if (getItemViewType(position) == TYPE_ITEM) {
                    View arrow = v.findViewById(R.id.Arrow_details);
                    if (isEnabled(position)) {
                        arrow.setVisibility(View.VISIBLE);
                    } else {
                        arrow.setVisibility(View.GONE);
                    }
                }
                return v;
            }

            @Override
            public boolean isEnabled(int position) {
                return tab != 2;
            }
        });
    } catch (Exception e) {
        Log.e(Constants.PROJECT_TAG, "JSONException in setAdapterForTab", e);
    }

}

From source file:planets.position.EclipseData.java

/**
 * Converts the given Julian Date to a String
 * /*from w  w w. j  a  v a2  s. c o m*/
 * @param jd
 *            - Julian Date to convert
 * @param local
 *            - Set if date/time is local
 * @return CharSequence of Date
 */
private CharSequence convertDate(double jd, boolean local) {
    if (jd > 0.0) {
        Calendar c = Calendar.getInstance();

        String[] dateArr = jd2utc(jd).split("_");
        c.set(Integer.parseInt(dateArr[1]), Integer.parseInt(dateArr[2]) - 1, Integer.parseInt(dateArr[3]),
                Integer.parseInt(dateArr[4]), Integer.parseInt(dateArr[5]));
        c.set(Calendar.MILLISECOND, (int) (Double.parseDouble(dateArr[6]) * 1000));
        if (local) {
            // convert c to local time
            c.add(Calendar.MINUTE, (int) (offset * 60));
        }
        return DateFormat.format("MMM d kk:mm", c);
    } else {
        return "-N/A-   ";
    }
}

From source file:com.ess.tudarmstadt.de.sleepsense.usersdata.UsersDataFragment.java

private void addToDb() {
    String date = String.valueOf(DateFormat.format("dd-MM-yyyy", calendarPicker));

    LocalTransformationDBMS db = new LocalTransformationDBMS(getActivity().getApplicationContext());
    db.open();//www . j  av  a  2 s.c  om
    if (idToUpdate > -1) {
        ContentValues values = new ContentValues();
        values.put(LocalTransformationDB.SLEEP_TIME_COLUMN_SLEEP, sleep);
        values.put(LocalTransformationDB.SLEEP_TIME_COLUMN_WAKE, wake);
        values.put(LocalTransformationDB.SLEEP_TIME_COLUMN_PRBLY, 0.0d);

        int rowUpdated = db.updateRow(LocalTransformationDB.TABLE_SLEEP_TIME, values,
                LocalTransformationDB.SLEEP_TIME_COLUMN_ID + " =?",
                new String[] { String.valueOf(idToUpdate) });

        Log.e(TAG, "number of rows edited:" + rowUpdated);

        for (TrafficData trD : sleepData) {
            if (trD.getTrafficId() == idToUpdate) {
                trD.setxValue(sleep);
                trD.setyValue(wake);
            }
        }
    } else {
        db.addSleepData(date, sleep, wake, 0.0d);
        sleepData.add(new TrafficData(date, -1, sleep, wake));
    }
    db.close();

    Collections.sort(sleepData, new Comparator<TrafficData>() {

        @Override
        public int compare(TrafficData arg0, TrafficData arg1) {
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy_hh:mm");
            int compareResult = 0;
            try {
                Date arg0Date = format.parse(arg0.getTrafficDate() + "_"
                        + new DecimalFormat("00.00").format(arg0.getxValue()).replaceAll("\\,", ":"));
                Date arg1Date = format.parse(arg1.getTrafficDate() + "_"
                        + new DecimalFormat("00.00").format(arg1.getxValue()).replaceAll("\\,", ":"));
                compareResult = arg0Date.compareTo(arg1Date);
            } catch (ParseException e) {
                e.printStackTrace();
                compareResult = arg0.getTrafficDate().compareTo(arg1.getTrafficDate());
            }
            return compareResult;
        }
    });

    mArrayAdapter.clear();
    mArrayAdapter.addAll(sleepData);
    ((com.ess.tudarmstadt.de.sleepsense.usersdata.UsersDataFragment.mArrayAdapter) mArrayAdapter).calcPrbly();

    mArrayAdapter.notifyDataSetChanged();

    // clear picker
    calendarPicker = Calendar.getInstance();
    sleep = 0.0d;
    wake = 0.0d;
    idToUpdate = -1;

}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_date_label(int button_id, Calendar cal) {
    Button date_button = (Button) findViewById(button_id);

    String date = translate_day_of_week(DateFormat.format("EEEE", cal.getTime()).toString()) + " "
            + DateFormat.getLongDateFormat(getApplicationContext()).format(cal.getTime());
    date_button.setText(date);//from   w  w  w . j  a v  a2 s  .com
}

From source file:org.andstatus.app.util.MyLog.java

public static String currentDateTimeFormatted() {
    String strTime = DateFormat.format("yyyy-MM-dd-HH-mm-ss", new Date(System.currentTimeMillis())).toString();
    if (strTime.contains("HH")) {
        // see http://stackoverflow.com/questions/16763968/android-text-format-dateformat-hh-is-not-recognized-like-with-java-text-simple
        strTime = DateFormat.format("yyyy-MM-dd-kk-mm-ss", new Date(System.currentTimeMillis())).toString();
    }//from w  w  w.j a  v  a2 s .  c o m
    return strTime;
}

From source file:com.pukulab.puku0x.gscalendar.CalendarActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calendar);

    // ?//w ww. j av  a2s . c o  m
    mBackKeyTimer = new CountDownTimer(2000, 2000) {
        @Override
        public void onTick(long millisUntilFinished) {
        }

        @Override
        public void onFinish() {
            mBackKeyPressed = false;
        }
    };

    // ?
    Bundle extras = getIntent().getExtras();

    // ?
    if (mLoginUser == null) {
        mLoginUser = (UserData) extras.getSerializable(ARGS_LOGIN_USER);
    }

    // 
    if (mDisplayedUser == null) {
        mDisplayedUser = (UserData) extras.getSerializable(ARGS_DISPLAYED_USER);
    }

    // ?
    if (mDisplayedDate == null) {
        mDisplayedDate = (Date) extras.getSerializable(ARGS_DISPLAYED_DATE);
        mLastDisplayedDate = mDisplayedDate;
    }

    // 
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // ?????????
        if (mDisplayedUser.usid != null && !mDisplayedUser.usid.equals(mLoginUser.usid)) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        // 
        actionBar.setTitle(mDisplayedUser.name);
        actionBar.setSubtitle(DateFormat.format(getString(R.string.date_year_month_day), mDisplayedDate));
    }

    // Retrieve the CalendarView
    mCalendarView = (MultiCalendarView) findViewById(R.id.calendarView);
    mProgressBar = (ProgressBar) findViewById(R.id.pb_detail);
    //mScheduleLayout = (LinearLayout) findViewById(R.id.scheduleList);

    // ?
    mScheduleDataList = new ArrayList<>();
    mDailyScheduleList = new ArrayList<>();
    mDailyScheduleaListAdapter = new ScheduleDataAdapter(CalendarActivity.this, 0, mDailyScheduleList);
    mDailyScheduleListView = (ListView) findViewById(R.id.lv_schedule);
    mDailyScheduleListView.setAdapter(mDailyScheduleaListAdapter);
    mDailyScheduleListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Schedule schedule = (Schedule) listView.getItemAtPosition(position);
            // ???
            mLastSchedule = new Schedule(schedule);

            // ??
            Intent intent = DetailActivity.createIntent(CalendarActivity.this, mLoginUser, mDisplayedUser,
                    schedule);
            int requestCode = DetailActivity.REQUEST_DETAIL;
            startActivityForResult(intent, requestCode);
        }
    });

    // Set the first valid day
    final Calendar firstValidDay = Calendar.getInstance();
    firstValidDay.add(Calendar.YEAR, -1);
    firstValidDay.set(Calendar.DAY_OF_MONTH, 1);
    firstValidDay.set(Calendar.HOUR_OF_DAY, 0);
    firstValidDay.set(Calendar.MINUTE, 0);
    firstValidDay.set(Calendar.SECOND, 0);
    firstValidDay.set(Calendar.MILLISECOND, 0);
    mCalendarView.setFirstValidDay(firstValidDay);

    // Set the last valid day
    final Calendar lastValidDay = Calendar.getInstance();
    lastValidDay.add(Calendar.YEAR, 1);
    lastValidDay.set(Calendar.HOUR_OF_DAY, 0);
    lastValidDay.set(Calendar.MINUTE, 0);
    lastValidDay.set(Calendar.SECOND, 0);
    lastValidDay.set(Calendar.MILLISECOND, 0);
    mCalendarView.setLastValidDay(lastValidDay);

    // ~
    mCalendarView.setFirstDayOfWeek(Calendar.SUNDAY);
    mCalendarView.setLastDayOfWeek(Calendar.SATURDAY);

    // Create adapter
    final CustomDayAdapter adapter = new CustomDayAdapter();

    // Set listener and adapter
    mCalendarView.setOnDayClickListener(this);
    mCalendarView.getIndicator().setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            //System.out.println("position:" + position);
            final Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis((mCalendarView.getFirstValidDay().getTimeInMillis()));
            cal.add(Calendar.MONTH, position);
            mStartDate = cal.getTime();
            cal.add(Calendar.MONTH, 1);
            mEndDate = cal.getTime();
            mViewPagerPosition = position;
            new DisplaySchedulesTask(CalendarActivity.this, mDisplayedUser, mDisplayedDate).execute(mStartDate,
                    mEndDate);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mCalendarView.setDayAdapter(adapter);

    // ????????
    mCalendarView.setViewPagerPosition(12);
}