首页 > 解决方案 > 如何在 Acumatica 中获取数据库时间和时区?

问题描述

我使用下面的代码在 Acumatica 中获取数据库时间。首先我在数据库中创建了一个存储过程,我通过如下代码调用它。

这在 SQL Server 中运行良好,但不适用于 MySQL。

存储过程:

DROP PROCEDURE IF EXISTS GetDBtime;

CREATE PROCEDURE GetDBtime()
BEGIN
    SELECT SYSDATE();
END

C#代码:

protected void UserPreferences_UsrKNDBTime_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
       var row = (UserPreferences)e.Row;

       if (row != null)
       {
           foreach (var results in PXDatabase.Execute("GetDBtime", new PXSPParameter[] { new PXSPOutParameter("dateTimere", PXDbType.DateTime, null) }))
           {
               DateTime? dbTime = (DateTime)results;

               if (dbTime != null)
               {
                   e.ReturnValue = dbTime;
               }
               break;
           }
       }
   }
}

标签: acumatica

解决方案


您不必自己实现 - Acumatica 框架中已经有一个函数可以为您提供服务器日期时间。只需调用PXTransactionScope.GetServerDateTime.


推荐阅读