2016-12-08 73 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();