2013-10-18 63 views
0

我想產生一個UNIX時間戳和必須發送具有錯誤與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; 

我不得不請求發送初始時間和響應時間的WebRequest這樣

{ 
    "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

回答

0

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

+0

哦......它是我的錯。我很抱歉的問題。我會關閉它 – aki003

1

這太複雜了!只是這樣做:

var unixTime = (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds + "000000";