我正在尝试打印datepicker
价值textbox
,但它打印8-9-2013(MM-dd-yyyy)
而不是打印9-9-2013
。
我的 MainActivity.java 是
package com.example.datepicker;
import java.util.Calendar;
import java.util.Date;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
Button button;
DatePicker picker;
TextView text;
String mydate=java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(TextView)findViewById(R.id.textView1);
picker=(DatePicker)findViewById(R.id.datePicker1);
button=(Button)findViewById(R.id.button1);
datepicker();
}
private void datepicker() {
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
text.setText(getCurrentDate());
}
private CharSequence getCurrentDate() {
StringBuilder sb=new StringBuilder();
sb.append("Current Date ").append(picker.getMonth()).append("-").append(picker.getDayOfMonth()).append("-").append(picker.getYear());
return sb;
}
});
}
}