Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以可在Azure移动服务(Javascript)中查询的方式保存DateTime_Javascript_C#_Datetime_Azure_Azure Mobile Services - Fatal编程技术网

以可在Azure移动服务(Javascript)中查询的方式保存DateTime

以可在Azure移动服务(Javascript)中查询的方式保存DateTime,javascript,c#,datetime,azure,azure-mobile-services,Javascript,C#,Datetime,Azure,Azure Mobile Services,我想将DateTime值保存到Azure Mobile Services后端javascript,但如果将其保存为DateTime,则无法在该日期查询。我之所以要这样做,是因为我想检索特定日期范围内的所有项目。我试图将它们保存为记号,但这也不起作用,因为数值太大了 有人有想法吗?这不正确-如果在JS后端保存日期时间日期值,则可以根据该日期进行查询。所有关系操作>=,通过将它们另存为滴答声,您是指毫秒时间值吗,例如2014-12-25 UTC的1419465600000?我已经尝试了这个表。whe

我想将DateTime值保存到Azure Mobile Services后端javascript,但如果将其保存为DateTime,则无法在该日期查询。我之所以要这样做,是因为我想检索特定日期范围内的所有项目。我试图将它们保存为记号,但这也不起作用,因为数值太大了


有人有想法吗?

这不正确-如果在JS后端保存日期时间日期值,则可以根据该日期进行查询。所有关系操作>=,通过将它们另存为滴答声,您是指毫秒时间值吗,例如2014-12-25 UTC的1419465600000?我已经尝试了这个表。wherefunctionfirstDate,lastDate{返回this.date>=firstDate&&this.date我在撒谎。工作。您现在实际上是我的英雄。
<html>
  <head>
    <title>Test site</title>
    <script src="http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.2.5.min.js"></script>
  </head>
  <body>
    <h1>Playing with Azure</h1>
    <button onclick="insertData();">Insert data</button>
    <button onclick="readData();">read data</button>
    <ul id='results'></ul>
    <script type="text/javascript">
        var client = new WindowsAzure.MobileServiceClient(
            "https://SERVICENAME.azure-mobile.net/",
            "APPLICATIONKEY"
        );
        var table = client.getTable("so");
        function handleError(err) {
            addLog('Error: ' + err);
        }
        function addLog(text) {
            var ul = document.getElementById('results');
            var li = document.createElement('li');
            li.appendChild(document.createTextNode(text));
            ul.appendChild(li);
        }
        function insertData() {
            table.insert({ myfield: 12, date: new Date(2014, 11, 1) }).then(function() {
                addLog('Inserted data in December');
                table.insert({ myfield: 11, date: new Date(2014, 10, 1) }).then(function() {
                    addLog('Inserted data in November');
                    table.insert({ myfield: 10, date: new Date(2014, 9, 1) }).then(function() {
                        addLog('Inserted data in October');
                        table.insert({ myfield: 9, date: new Date(2014, 8, 1) }).then(function() {
                            addLog('Inserted data in Setember');
                        }, handleError);
                    }, handleError);
                }, handleError);
            }, handleError);
        }

        function readData() {
            var firstDate = new Date(2014, 8, 15);
            var lastDate = new Date(2014, 10, 15);
            table.where(function(firstDate, lastDate) {
                return this.date >= firstDate && this.date <= lastDate;
            }, firstDate, lastDate).read().done(function(results) {
                addLog('Results.length: ' + results.length);
                for (var i = 0; i < results.length; i++) {
                    addLog('Results[' + i + ']: ' + JSON.stringify(results[i]));
                }
            }, handleError);
        }
    </script>
  </body>
</html>
private static MobileServiceClient client = new MobileServiceClient(
    "https://SERVICENAME.azure-mobile.net", "APPLICATION_KEY");
private static IMobileServiceTable<MyType> table = client.GetTable<MyType>();

private async void InsertData_Click(object sender, EventArgs args) {
    for (int month = 12; month >= 9; month--) {
        var date = new DateTime(2014, month, 1, 0, 0, 0, DateTimeKind.UTC);
        await table.InsertAsync(new MyType { date = date, myfield = month });
    }
}

private async void ReadData_Click(object sender, EventArgs args) {
    var firstDate = new DateTime(2014, 9, 15, 0, 0, 0, DateTimeKind.UTC);
    var lastDate = new DateTime(2014, 11, 15, 0, 0, 0, DateTimeKind.UTC);
    var items = await table
        .Where(t => t.date >= firstTime && t.date <= lastTime)
        .ToListAsync();
    foreach (var item in items) {
        AddLog("Read item: " + item);
    }
}

public class MyType {
    public string id { get; set; }
    public DateTime date { get; set; }
    public int myfield { get; set; }
}