如何在我的时间表中显示日期(例如,01/10/2015)而不是日期(例如,星期一,星期二)

时间:2015-01-10 10:10:04

标签: java android datetime google-calendar-api

我的桌子只能显示天数。我想显示动态日期而不是天活动。如何显示它。这是我的日活动代码:

   protected void onPostExecute(Void result) {
        //close the progress dialog
        progressDialog.dismiss();
        //initialize the View
        if ((res1 != null) && (res1.getHttpCode() == 200)) {

            ViewPager pager = (ViewPager) timetable.findViewById(R.id.pager_day);

            String res = res1.getBody();           

            week = new Gson().fromJson(res, ExamWeeklyTimetable.class );

            if ((week.getMondayActivities().size() == 0) && (week.getTuesdayActivities().size() == 0) &&
                    (week.getWednesdayActivities().size() == 0) && (week.getFridayActivities().size() == 0) &&
                    (week.getThursdayActivities().size() == 0) && (week.getSaturdayActivities().size() == 0) &&
                    (week.getSundayActivities().size() == 0)) {
                RelativeLayout rl = (RelativeLayout) timetable.findViewById(R.id.semesterDay);
                rl.removeAllViews();
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                rl.addView(View.inflate(timetable.getContext(), R.layout.fragment_layout_timetable_fail, null), params);
             } else 
            {
                Calendar calendar = Calendar.getInstance();
                int day = calendar.get(Calendar.DAY_OF_WEEK);
     //                    Calendar c = Calendar.getInstance(); 
     //                    int date = c.get(Calendar.DAY_OF_MONTH);

                pager.setAdapter(buildAdapter(res));
                if (day == 1) {
                    int finalDay = 6;
                    pager.setCurrentItem(finalDay);
                } else {
                    int finalDay = day - 2;
                    pager.setCurrentItem(finalDay);
                }

                pager.setOffscreenPageLimit(7);
            }

下面是ExamWeeklyTimetable.java的课程

   package com.tp.cis.mobile.ExamTimetable;

  import java.util.List;

  import com.tp.cis.mobile.Classes.Activity;

  public class ExamWeeklyTimetable {
 String AcademicYear;
    List<Activity> MondayActivities;
    List<Activity> TuesdayActivites;
    List<Activity> WednesdayActivities;
    List<Activity> ThursdayActivities;
    List<Activity> FridayActivities;
    List<Activity> SaturdayActivities;
    List<Activity> SundayActivities;
    List<Activity> WholeWeekActivities;
    String SemesterName;

    public String getAcademicYear() {
        return AcademicYear;
    }

    public void setAcademicYear(String academicYear) {
        this.AcademicYear = academicYear;
    }

    public List<Activity> getMondayActivities() {
        return MondayActivities;
    }

    public void setMondayActivities(List<Activity> mondayActivities) {
        this.MondayActivities = mondayActivities;
    }

    public List<Activity> getTuesdayActivities() {
        return TuesdayActivites;
    }

    public void setTuesdayActivities(List<Activity> tuesdayActivities) {
        this.TuesdayActivites = tuesdayActivities;
    }

    public List<Activity> getWednesdayActivities() {
        return WednesdayActivities;
    }

    public void setWednesdayActivities(List<Activity> wednesdayActivities) {
        this.WednesdayActivities = wednesdayActivities;
    }

    public List<Activity> getThursdayActivities() {
        return ThursdayActivities;
    }

    public void setThursdayActivities(List<Activity> thursdayActivities) {
        this.ThursdayActivities = thursdayActivities;
    }

    public List<Activity> getFridayActivities() {
        return FridayActivities;
    }

    public void setFridayActivities(List<Activity> fridayActivities) {
        this.FridayActivities = fridayActivities;
    }

    public List<Activity> getSaturdayActivities() {
        return SaturdayActivities;
    }

    public void setSaturdayActivities(List<Activity> saturdayActivities) {
        this.SaturdayActivities = saturdayActivities;
    }

    public List<Activity> getSundayActivities() {
        return SundayActivities;
    }

    public void setSundayActivities(List<Activity> sundayActivities) {
        this.SundayActivities = sundayActivities;
    }

    public List<Activity> getWholeWeekActivities() {
        return WholeWeekActivities;
    }

    public void setWholeWeekActivities(List<Activity> wholeWeekActivities) {
        this.WholeWeekActivities = wholeWeekActivities;
    }

    public String getSemesterName() {
        return SemesterName;
    }

    public void setSemesterName(String semesterName) {
        this.SemesterName = semesterName;
    }

}

2 个答案:

答案 0 :(得分:0)

如果您希望格式中的日期生成类似的方法并在日期选择器对话框中调用该方法

private void updateLabel() 
{
    String myFormat = "MM/dd/yy"; //In which formt you need put here
    SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

   // JoiningDate.setText(sdf.format(myCalendar.getTime()));
}

希望它有所帮助...

答案 1 :(得分:0)

添加此

 Date d = new Date(year, month, day);
 SimpleDateFormat dateFormatter = new SimpleDateFormat(
            "MM-dd-yyyy");
 strDate = dateFormatter.format(d);