提问人:xceed 提问时间:7/28/2015 最后编辑:xceed 更新时间:10/7/2015 访问量:197
按应用查询时 Azure 移动服务字符串/日期列的问题
Issue with Azure mobile service string/date column when queried by app
问:
我在 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:00
System.FormatException: String was not recognized as a valid DateTime.
DateTime.Parse
我真的不确定为什么会这样,我知道我可能应该将列设置为类型 date,但忘记了它是一个日期,作为一个字符串,它应该像在 Azure 中一样显示,或者至少这是我想发生的。
答:
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);
评论
MyTable
InputDate
String
DateTime
string