2011-10-12 60 views
0

提醒日期是美國格式(mm/dd/yyyy)默認情況下,我猜。如何操縱提醒的收集和格式化日期英國格式,以便在列表框中將顯示提示如下:如何在提醒中操作日期格式

開始時間(英國格式或非美國格式)
內容

 

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 : 



&ltListBox Name="ReminderListBox" Margin="1,116,-2,4" > 
    &ltListBox.ItemTemplate> 
     &ltDataTemplate> 
     &ltGrid Background="Transparent" Margin="0,0,0,30"> 

     &ltStackPanel Orientation="Horizontal" >          

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

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


 

問題:我不想在列表框中設置日期格式。我想動態檢測語言環境並顯示日期格式基於檢測到的語言環境Ex非美國格式Jpn,Kor,中國

回答

1

您的列表框模板是什麼樣的?你應該能夠使用格式說明符「d」(短日期)或「D」(長日期)來選擇文化的「正確」日期格式......我希望你是能夠從XAML做到這一點,而不是改變其他任何東西。

請注意,DateTime本身不具有格式 - 所以它不像你可以設置該值爲「in」英國格式。

編輯:我覺得想:

{Binding BeginTime, StringFormat=d} 

,或者如果你想特定格式(我不推薦)

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

感謝。我剛剛更新了我的問題。我想要的是檢測手機的語言環境,然後根據它顯示日期格式。那麼,如何獲取日期格式。謝謝 – MilkBottle

+0

@MilkBottle:看看編輯是否可以幫助你... –

+0

是的。這是我想要的。問題是(1)如果電話區域設置爲臺灣,ListBox DataTemplate中的{Binding BeginTime,StringFormat = d}將如何顯示?會顯示DD/MM/YYYY嗎? (2)如何將此stringFormat動態傳遞給ListBox DataTemplate?謝謝 – MilkBottle