Lambda的新功能。這個問題特別針對Lambda表達式來操作日期格式。用於獲取所有從調度系統提醒下面的代碼:如何使用Lambda表達式來格式化日期
MyReminders = ScheduledActionService.GetActions().Where(
a => a.BeginTime.Date == Today
);
有可能返回結果集之前更改日期格式。
.where ( a => a.BeginTime.Date == Today).Select( //the date and format BeginTime.date.ToString("d", new cultureInfo("zh-CN")) )
更改日期格式如下,但這將工作在lambda表達式嗎?
BeginTime.Date.ToString("d",new cultureInfo("zh-CN"),
感謝,並感謝您的幫助。
------------更新:
我嘗試這兩種方法。在列表框中沒有顯示任何結果:
此調度程序系統用於windows phone 7.此提醒對象包含以下屬性: 1)BeginTime,2)ExpirationTime,3)Title,4)Content,5)isSchedule和其他
檢索後,我需要DataBind它到一個列表框。 ReminderListBox.ItemsSource = MyReminders;
1) var czech = new CultureInfo("zh-CN");
var MyReminders = ScheduledActionService.GetActions<Reminder>()
.Where(a => a.BeginTime.Date == Today)
.Select(a =>
new
{
Begindate = a.BeginTime.Date.ToString("d", czech),
Title = a.Title,
Content = a.Content
});
2) var czech = new CultureInfo("zh-CN"); var MyReminders = ScheduledActionService.GetActions() .Where(a => a.BeginTime.Date == Today) .Select(a => a.BeginTime.Date.ToString("d", czech));
< ListBox Name="ReminderListBox" >
< ListBox.ItemTemplate>
< DataTemplate>
< Grid Background="Transparent" Margin="0,0,0,30">
< StackPanel Orientation="Vertical" >
< TextBlock FontSize="23" Text="{Binding Title}"/ >
< TextBlock FontSize="23" Text="{Binding Content}" />
< StackPanel Orientation="Horizontal">
< TextBlock Text="begin "/>
< TextBlock x:Name="txtDate" Text="{Binding BeginTime}" />
< /StackPanel>
< StackPanel Orientation="Horizontal">
< TextBlock Text="expiration "/>
< TextBlock Text="{Binding ExpirationTime}"/>
< /StackPanel>
< StackPanel Orientation="Horizontal">
< TextBlock Text="recurrence "/>
< TextBlock Text="{Binding RecurrenceType}" />
< /StackPanel>
< StackPanel Orientation="Horizontal">
< TextBlock Text="is scheduled? "/>
< TextBlock Text="{Binding IsScheduled}"/>
< /StackPanel>
< /StackPanel>
< /Grid>
< /DataTemplate>
< /ListBox.ItemTemplate>
< /ListBox>