2016-12-08 74 views
0

TimeJobSubmitted屬性似乎不會在正確的時區中返回時間。當我手動查看Windows中的打印隊列時,我可以看到工作時間是正確的。 (例如:顯示在3:30提交的Job1);PrintSystemJobInfo.TimeJobSubmitted報告錯誤時間?

問題是使用PrintJobInfoCollection解析代碼中的打印作業時,它似乎沒有使用正確的時區,因爲它表示TimeJobSubmitted是8:30,與正確的值相反,3:30顯示在在窗口中看到的實際打印隊列。 (右鍵單擊打印機,並單擊「看看有什麼打印」看到打印隊列中的窗口。

這是我如何通過在代碼中的打印隊列中查看。

  LocalPrintServer server = new LocalPrintServer(); 
      PrintQueue pq = server.GetPrintQueue(printerName); 

      if (pq != null) 
      { 
       pq.Refresh(); 
       PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection(); 
       foreach (PrintSystemJobInfo job in jobs) 
       { 
        string jobName = job.Name; 
        string jobStatus = job.JobStatus.ToString(); 
        // Why is the next line 5 hours off of the correct time? 
        DateTime timeSubbited = job.TimeJobSubmitted; 
        DateTime currentTime = DateTime.Now;; 
        TimeSpan elapsed = currentTime - timeSubbited; 

        // double minutesPassed = timePassed.TotalMinutes; 

       } 
      } 

我如何得到正確的TimeJobSubmitted在C#迭代的打印作業時?

回答

1

這已經有一段時間,因爲我有日期時間的工作。我應該知道,據報道,在UTC。正確答案是簡單地調用.ToLocalTime()

job.TimeJobSubmitted.ToLocalTime();