开发者

How to manipulate the date format in reminders

开发者 https://www.devze.com 2023-04-12 04:56 出处:网络
The date in reminder is US format ( mm/dd/yyyy) By default I guess. How to manipulate the collection of reminders and format the date to british formatso that the listBox will show the reminders as be

The date in reminder is US format ( mm/dd/yyyy) By default I guess. How to manipulate the collection of reminders and format the date to british format so that the listBox will show the reminders as below:

Begin Date ( in British Format or non-US format)

Content


MyReminders = ScheduledActionService.GetActions()
                .Where(a => a.BeginTime.Date == Today);

 foreach (Reminder r in MyReminders)
{
 // How to change the date format to British  in each of the reminder and display 
    in the listBox?

}

   ReminderListBox.ItemsSource = MyReminders;


In the list Box :



<ListBox Name="ReminderListBox" Margin="1,116,-2,4" >
   <ListBox.ItemTemplate>
      <DataTemplate>
        <Grid Background="Transparent" Margin="0,0,0,30">   

         <StackPanel Orientation="Horizontal" >                                       

         <TextBlock Text="begin "/>
         <TextBlock Text="{Binding BeginTime}" HorizontalAlignment="Right"/>
          </StackPanel>

               </Grid>
         </DataTemplate/>
    </ListBox.ItemTemplate/>
 </ListBox />              



problems : I dont want to set the date format in the listbox. I want to dynamically detect the locale and display the date Form开发者_运维技巧at base on the detected locale Ex Non-US format for Jpn, Kor, China


What does your listbox template look like? You should be able to make it pick the "right" date format for the culture using a format specifier of "d" (for short date) or "D" (for long date) ... and I'd expect you to be able to do that from XAML rather than changing anything else.

Note that the DateTime itself doesn't have a format - so it's not like you could set that value to be "in" UK format.

EDIT: I think you want:

{Binding BeginTime, StringFormat=d}

or if you want to force a specific format (which I don't recommend)

{Binding BeginTime, StringFormat=dd/MM/yyyy}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号