2

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

问题是在PrintJobInfoCollection使用TimeJobSubmitted视窗。(右键单击打印机并单击“查看正在打印的内容”以查看 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?

4

1 回答 1

2

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

job.TimeJobSubmitted.ToLocalTime();
于 2016-12-08T21:06:27.313 回答