【问题标题】:PrintSystemJobInfo.TimeJobSubmitted Reports Wrong Time?PrintSystemJobInfo.TimeJobSubmitted 报告错误时间?
【发布时间】:2016-12-08 20:56:44
【问题描述】:

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?

【问题讨论】:

    标签: c# printing printqueue


    【解决方案1】:

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

    job.TimeJobSubmitted.ToLocalTime();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 2010-11-03
      • 2015-04-20
      • 2022-10-31
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      相关资源
      最近更新 更多