現在、datepickerはm/d/yyyy形式のテキストビューに日付を設定していますが、dateformatをm/d/yyyyからdd-mm-yyyyに変更したいとします。私はこのtopic.butを見つけた解決策を見つけませんでした。xamarin androidの日付書式を変更する
Main.axml
<TextView
android:layout_weight="80"
android:id="@+id/dateDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date" />
<Button
android:layout_weight="10"
android:id="@+id/pickDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick date" />
mainactivity.cs
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
SetContentView(Resource.Layout.Main);
dateDisplay = FindViewById<TextView> (Resource.Id.dateDisplay);
pickDate = FindViewById<Button> (Resource.Id.pickDate);
// add a click event handler to the button
pickDate.Click += delegate { ShowDatePickerDialog(); };
// get the current date
//date = DateTime.Today;
// display the current date (this method is below)
// UpdateDisplay (date);
}
void ShowDatePickerDialog()
{
var dialog = new DatePickerFragment(this, DateTime.Now, this);
dialog.Show(FragmentManager, null);
}
public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
var newDate = new DateTime(year, monthOfYear + 1, dayOfMonth);
UpdateDisplay(newDate);
}
void UpdateDisplay(DateTime selectedDate)
{
// selectedDate.GetDateTimeFormats('d');
// dateDisplay.Text = selectedDate.GetDateTimeFormats('d').ToString();
dateDisplay.Text = selectedDate.ToString("d");
}
}
DatePickerFragment.cs
public class DatePickerFragment : DialogFragment
{
private readonly Context context;
private DateTime date;
private readonly DatePickerDialog.IOnDateSetListener listener;
public DatePickerFragment(Context context, DateTime date, DatePickerDialog.IOnDateSetListener listener)
{
this.context = context;
this.date = date;
this.listener = listener;
}
public override Dialog OnCreateDialog(Bundle savedState)
{
var dialog = new DatePickerDialog(context, listener, date.Year, date.Month - 1, date.Day);
return dialog;
}
}
'dd-MM-yyyy'フォーマットの' DateTime'はどこに表示されますか?それはここにあります: 'dialog.Show(FragmentManager、null);'? 'FragmentManager'のデータ型は?形式は単なる表現である。 'DateTime'構造体自体にはフォーマットはありません。 – Ian
@Ian私はテキストビューで設定または表示しています.31-04-2015(date-month-year)の日付を表したい – dafodil
OK、コードのその部分を表示できますか?どのようにあなたは、ビューに渡すデータ型だけでなく、ビューに表示する... – Ian