---
title: "SAP 计算时间-MTIME"
author: "evangxli"
date: "2011-05-10T18:48:24Z"
tags: []
categories: ["编程语言"]
slug: "sap-mtime"
draft: false
lastmod: "2011-05-10T18:48:24Z"
id: 1039347
url: "https://sapabap.iteye.com/blog/1039347"
---

计算时间字段的值,例如Structure EMG_FILEINFO 中的字段 MTIME,字段描述:Last modification: seconds since 1970.

SAP include **LEMIG_LISTF01**
form **GET_DAT_TIME**


```java
form get_dat_time using    p_mtime
                           p_date
                           p_time.

  tables: ttzr, ttzz.

  data: tage type i,
        seku type i,
        uzeit type t,
        sdatum type d value '19700101',
        tzone like ttzdata-tzone.

  tage = p_mtime div 86400.
  seku = p_mtime mod 86400.
  p_date = sdatum + tage.

  if ttzz is initial.
    call function 'TZ_LOCATION_TIMEZONE'
         exporting
              country           = 'DE'
         importing
              timezone          = tzone
         exceptions
              no_timezone_found = 1
              others            = 2.

    select single * from ttzz where tzone eq tzone.
    select single * from ttzr where zonerule eq ttzz-zonerule.
  endif.

  if ttzr-utcsign eq '+'.
    uzeit = seku + ttzr-utcdiff.
  else.
    uzeit = seku - ttzr-utcdiff.
  endif.

  p_time = uzeit.


endform.                               " GET_DAT_TIME
```