PrintSystemJobInfo.TimeJobSubmitted报告错误的时间?

时间:2016-12-08 20:56:45

标签: c# printing printqueue

TimeJobSubmitted属性似乎没有在正确的时区中返回时间。当我手动查看Windows中的打印队列时,我可以看到作业中的时间是正确的。 (示例:显示在3:30提交的Job1);

问题是当使用PrintJobInfoCollection在代码中解析打印作业时,它似乎没有使用正确的时区,因为它说TimeJobSubmitted是8:30,而不是正确的值,在窗口中看到的实际打印队列中显示3:30。 (右键单击打印机,然后单击“查看打印内容”以查看Windows中的打印队列。

以下是我在代码中查看打印队列的方法。

            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;

                }
            }

在c#中迭代打印作业时,如何获得正确的TimeJobSubmitted?

1 个答案:

答案 0 :(得分:1)

自从我使用DateTime以来已经有一段时间了。我应该知道它是用UTC报道的。正确的答案是简单地拨打.ToLocalTime()

job.TimeJobSubmitted.ToLocalTime();