Unix 时间生成时出错
本文关键字:出错 时间 Unix | 更新日期: 2023-09-27 18:35:48
我正在尝试生成一个 unix 时间戳,并且必须发送具有初始时间和响应时间的网络请求
我试过这段代码
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
这太复杂了!只需这样做:
var unixTime = (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds + "000000";
将
string timestamp2 = ticks.ToString() + "000000";
更改为string timestamp2 = ticks2.ToString() + "000000";