我正在尝试从 Google 日历中获取事件并将它们显示在 Xamarin.Forms 的列表视图中。当您调用 start.dateTime 时,Google 日历使用 RFC3339 格式,格式为 yyyy-mm-dd。我正在尝试执行类似于 .Net DateTime.ToLongDateString 方法的字符串星期几格式(2018 年 1 月 1 日星期一)。到目前为止,我的代码是这样的:namespace TheFirstAcademy.ViewModels{class EventListViewModel{ public List<SchoolEvent> SchoolEvents { get; set; } public SchoolCalendar SelectedCalendar { get; set; } public EventListViewModel(SchoolCalendar selectedcalendar) { SelectedCalendar = selectedcalendar; SchoolEvents = GetSchoolEvents(); } public List<SchoolEvent> GetSchoolEvents() { // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() { ApiKey = "Key", ApplicationName = "TFA Calendar Mobile App", }); // Define parameters of request. EventsResource.ListRequest request = service.Events.List(SelectedCalendar.SchoolCalId); request.TimeMin = DateTime.Now; request.ShowDeleted = false; request.SingleEvents = true; request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; // List events. Events events = request.Execute(); List<SchoolEvent> schoolEvents = new List<SchoolEvent>(); if (events.Items != null && events.Items.Count > 0) { foreach (var eventItem in events.Items) { string when = eventItem.Start.DateTime.ToString(); if (String.IsNullOrEmpty(when)) { when = eventItem.Start.Date; }这最终将使用 Xamarin.Forms 显示在 iOS 和 Android 的 ListView 中。
1 回答
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消