0

如何在 PHP 中创建可由 .NET 的非标准日期格式读取的日期字符串:

例如,鉴于此 PHP 代码:

$fetch = mysql_query("SELECT birthday FROM people"); 
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
    $birthday = $row['birthday'];
    $json = ??? // some way to convert it to the .net json format
}

如何操作 PHP 日期以返回 C#/.Net 的 json 反序列化方法所期望的这种 JSON 样式:

{"birthday":"\/Date(1331550000000)\/"}
4

2 回答 2

3

The .NET format is Milliseconds from the Epoch - so the following format worked for me

 $date = '/Date('.(date("U",time())*1000).'-0500)/';
于 2012-12-03T19:58:51.323 回答
0

.Net 的 json 反序列化方法可以接受任何 json 数据。您可以像下面这样构建 json。

$fetch = mysql_query("SELECT birthday FROM people"); 
$birthdays = array();
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
    $birthdays[] = $row;
}
$json = json_encode($birthdays);
echo $json;
于 2012-07-03T01:48:31.380 回答