0

我正在尝试以 dd/MM/yyyy 格式显示从今天开始的特定时间范围。这是我的代码:

Calendar c = Calendar.getInstance();
    int mYear = c.get(Calendar.YEAR);
    int mMonth = c.get(Calendar.MONTH);
    int mDay = c.get(Calendar.DAY_OF_MONTH);

    // display the current date
    String CurrentDate = mYear + "/" + mMonth + "/" + mDay;

    String dateInString = CurrentDate; // Start date
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    c = Calendar.getInstance();

    try {
        c.setTime(sdf.parse(dateInString));
    } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    c.add(Calendar.DATE, 7656);//insert the number of days you want to be added to the current date
    sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date resultdate = new Date(c.getTimeInMillis());
    dateInString = sdf.format(resultdate);

    TextView newDate = (TextView) findViewById(R.id.dispNewPayoffDate);
    newDate.setText(dateInString);

这是 dispNewPayoffDate 的布局部分:

<TextView
    android:id="@+id/dispNewPayoffDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textNewPayoffDate"
    android:layout_alignBottom="@+id/textNewPayoffDate"
    android:layout_alignLeft="@+id/dispOriginalPayoffDate"
    android:inputType="date|text"
    android:text="01/01/9998" />

由于某些(对我而言)未知的原因,日期显示为 MM/dd/yyyy。

关于如何翻转月份和日期的任何建议?

4

1 回答 1

1

我想我偶然找到了答案 - 当前:

<TextView
android:id="@+id/dispNewPayoffDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textNewPayoffDate"
android:layout_alignBottom="@+id/textNewPayoffDate"
android:layout_alignLeft="@+id/dispOriginalPayoffDate"
android:inputType="date|text"
android:text="01/01/9998" />

新的:

<TextView
android:id="@+id/dispNewPayoffDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textNewPayoffDate"
android:layout_alignBottom="@+id/textNewPayoffDate"
android:layout_alignLeft="@+id/dispOriginalPayoffDate"
android:inputType="text"         <---------- took away date
android:text="01/01/9998" />
于 2013-11-10T01:05:35.917 回答