我正在嘗試將 SQL 結果從我的 PHP 制作的網站傳遞到我使用 Xamarin Forms 制作的 C# APP。我通過在我的 PHP 應用程序中創建一個 REST API 端點并因此通過我的 C# 應用程序調用 URL 來做到這一點。這將返回一個帶有我的結果的 Json 數組。但是,我找不到任何方法來解析我收到的日期時間對象到 c# datetime,因為它在我無法擺脫的日期時間后面有“.00000”。SQL$query = $this->createQueryBuilder('c') ->select('partial c.{id, image, title,contentType, createdOn }', 'partial cd.{id, data}', 'partial u.{id, email} ', 'partial ud.{id, screenName, profileImage} ') ->join('c.data', 'cd') ->join('c.user', 'u') ->join('u.data', 'ud') ->andWhere('c.user !=:user') ->setParameters( array( 'user' => $this->janVanAllemanId ) ) ->orderBy('c.modifiedOn', 'DESC') ->setFirstResult($offset) ->setMaxResults($limit) ->getQuery(); $results = $query->getArrayResult();JSON 數組 { "posts": [ { "id": 3373, "contentType": 6, "createdOn": { "date": "2019-05-21 14:00:14.000000", "timezone_type": 3, "timezone": "Europe/Amsterdam" }, ... }, { "id": 3371, "contentType": 6, "createdOn": { "date": "2019-05-18 14:30:09.000000", "timezone_type": 3, "timezone": "Europe/Amsterdam" }, ... } ]}如您所見,它返回一個包含"date"、"timezone"和"timezone_type"的數組。在我的一生中,我無法使用它將其解析為 C# DateTime 對象。
1 回答

牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
你可以使用這個:CreatedOnDateTime = DateTime.Parse(value["date"].ToString(), CultureInfo.CreateSpecificCulture("nl-NL"));
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消