ABAP CDS如何取得当前系统日期和系统时间

CDS中的日期和时间

在这里插入图片描述

$session.system_date

$session.system_date			系统时间,SY-DATUM

TSTMP_CURRENT_UTCTIMESTAMP( )

TSTMP_CURRENT_UTCTIMESTAMP( )取得当前时间戳;

tstmp_current_utctimestamp() as Time3,//当前时间戳
substring(cast(tstmp_current_utctimestamp()as abap.char(17)),1,8)as Time1,//当前日期
substring(cast(tstmp_current_utctimestamp()as abap.char(17)),9,6)as Time2,//当前时间

使用需要注意时区问题

日期/时间转换的SQL函数目前只能在Core Data Service中使用,OPEN SQL不能使用。

· TSTMP_TO_DATS( tstmp, tzone, clnt, on_error )将时间戳的日期部分转为d类型

· TSTMP_TO_TIMS( tstmp, tzone, clnt, on_error )将时间戳的时间部分转换为t类型

· DATS_TIMS_TO_TSTMP( date, time, tzone, clnt, on_error )将日期和时间拼成时间戳

· ABAP_SYSTEM_TIMEZONE( clnt, on_error )取得系统时区

· ABAP_USER_TIMEZONE( user, clnt, on_error )取得用户主数据的时区

举例:

@AbapCatalog.sqlViewName: 'demo_cds_datim'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_date_time
  as select from
    demo_expressions
    {
      tstmp_current_utctimestamp() as tstmp,
      tstmp_to_dats( tstmp_current_utctimestamp(),
                     abap_system_timezone( $session.client,'NULL' ),
                     $session.client,
                     'NULL' )      as dat,
      tstmp_to_tims( tstmp_current_utctimestamp(),
                     abap_system_timezone( $session.client,'NULL' ),
                     $session.client,
                     'NULL' )      as tim,
      tstmp_to_dst( tstmp_current_utctimestamp(),
                    abap_system_timezone( $session.client,'NULL' ),
                    $session.client,
                    'NULL' )       as dst,
      dats_tims_to_tstmp( dats1,
                          tims1,
                          abap_system_timezone( $session.client,'NULL' ),
                          $session.client,
                         'NULL' )  as dat_tim
    }    

取年月日时分秒

concat( 
               cast( $session.system_date as abap.char(8) ),
               cast( tstmp_to_tims( tstmp_current_utctimestamp(), //取得时间戳
                     //abap_system_timezone( $session.client,'NULL'),//取得系统时区
                     'UTC+8',
                     $session.client,
                     'NULL')as abap.char(6) ) 
              ) as Time, //时间

在这里插入图片描述
2021年08月12日11时34分54秒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值