按应用查询时 Azure 移动服务字符串/日期列的问题

Issue with Azure mobile service string/date column when queried by app

提问人:xceed 提问时间:7/28/2015 最后编辑:xceed 更新时间:10/7/2015 访问量:197

问:

我在 Azure 上有一个移动服务,我的一个列(名为 InputDate)设置为字符串类型。示例值为 (ISO 8601 格式)2015-07-23T18:00:00Z

但是,当我使用以下代码查询此表时:

List<MyTable> MyTableData = await TheTable.Where(t => t.Name == "test")
                                          .OrderByDescending(t => t.__createdAt)
                                          .ToListAsync();

然后当我使用以下方法打印出日期时:

Debug.WriteLine(MyTableData[MyTableData.Count-1].InputDate);

它看起来像这样,这是一种完全不同的格式,不包括 T/Z 分隔符,当我以日期作为参数调用时也会导致异常。07/23/2015 18:00:00System.FormatException: String was not recognized as a valid DateTime.DateTime.Parse

我真的不确定为什么会这样,我知道我可能应该将列设置为类型 date,但忘记了它是一个日期,作为一个字符串,它应该像在 Azure 中一样显示,或者至少这是我想发生的。

C# 日期时间 Azure

评论

0赞 Matt Johnson-Pint 7/28/2015
你的类是否定义为 also?还是作为 ?MyTableInputDateStringDateTime
0赞 xceed 7/28/2015
是的,它的类型是string
0赞 xceed 7/31/2015
我可以尝试使用 Wireshark 或其他东西来查看来自 Azure 的原始响应实际包含的内容,以查看它是 Azure 端还是我的应用程序。还是完全被这个难住了!
0赞 Stuart Smith 8/20/2015
你能包括TheTable类吗

答:

0赞 dgiard 10/7/2015 #1

尝试使用 DateTime.ParseExact 静态函数将“DateTime”字符串属性转换为日期时间。

例如: 字符串 strDate = “2015-07-23T18:00:00”; 日期时间 mydate = DateTime.ParseExact(strDate, “yyyy-MM-ddTHH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture);