我可以在DATETIME找到第一次和第二次的总时间吗?

时间:2015-10-15 07:31:20

标签: c#

我想找到2 DATETIME的总时间。现在我有2个DATETIMES:loginDT和logoutDT。对于loginDT,我从数据库获取,现在是logoutDT。比如下面的代码

DateTime loginDT = (DateTime)readerS["login_Date_Time"];
DateTime logoutDT = DateTime.Now;
DateTime total = ??????????????

我该怎么办? 全部谢谢

3 个答案:

答案 0 :(得分:0)

C#中的时间间隔用TimeSpan结构测量。您可以通过减去两个DateTime变量来获得它:

DateTime loginDT = (DateTime)readerS["login_Date_Time"];
DateTime logoutDT = DateTime.Now;
TimeSpan total = logoutDT - loginDT;

答案 1 :(得分:0)

DATA: lt_query_data  TYPE osreftab,
      lt_query_table TYPE REF TO data.

FIELD-SYMBOLS <fs_table>.


lt_query_data = zca_ps_user=>agent->if_os_ca_persistency~get_persistent_by_query(
  i_query = cl_os_system=>get_query_manager( )->create_query( )
  ).

  CALL METHOD zcl_ps_object_to_structure_hlp=>reftab_to_structure_list
    EXPORTING
      it_refrence_table          = lt_query_data
    RECEIVING
      rr_object_attributes_table = lt_query_table.

  IF lt_query_table IS INITIAL.
    LEAVE.
  ENDIF.

  ASSIGN lt_query_table->* TO <fs_table>.

*Create a ALV

  DATA: lr_alv TYPE REF TO cl_salv_table .

  cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv
    CHANGING t_table = <fs_table> )
      .

  lr_alv->display( ).

答案 2 :(得分:0)

看来,你想要这样的东西:

  DateTime loginDT = (DateTime)readerS["login_Date_Time"];
  DateTime logoutDT = DateTime.Now;

  //TODO: have look at TotalHours, TotalSeconds, TotalMilliseconds 
  // Difference in Days; 
  // store this value as a Number field of the RDBMS table
  Double totalDays = (logoutDT - loginDT).TotalDays;