0

我正在尝试生成一个 unix 时间戳,并且必须发送一个具有初始时间和响应时间的 webrequest

我试过这段代码

long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
ticks /= 10000;
string timestamp = ticks.ToString() + "000000";
label1.Text = timestamp;
int k=0;
for (int i = 0; i < 100; i++)
{
   k = k + i;
}
long ticks2 = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
ticks2 /= 10000;
string timestamp2 = ticks.ToString() + "000000";
label2.Text = timestamp2;

我必须像这样发送请求

{
    "options": {
        "events": [
            {
                "event_type": 13,
                "view_type": 1,
                "view_parameter": 92,
                "request_identifier": %2",
                "time": 1382060060538000000,
                "event_data": {}
            }
        ],
        "report_time": 1382060072238000000
    },
    "context": {
        "app_version":"6590b21"
    }
}

错误是,两个标签框上的输出都相同http://prntscr.com/1y0v7p

4

2 回答 2

1

这太复杂了!只需这样做:

var unixTime = (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds + "000000";
于 2013-10-18T02:13:37.073 回答
0

更改string timestamp2 = ticks.ToString() + "000000";string timestamp2 = ticks2.ToString() + "000000";

于 2013-10-18T01:52:49.570 回答