關於sap的日期,時間

來源:互聯網
上載者:User

1.日期類型(D,Date)
在sap裡Date類型通過隱含的轉換函式變為CHARACTER*8.
Elementary data type = D 內部長度和 輸出長度都等於8
System data type = DATS 內部長度 = 8 輸出長度 = 10
所有的日期類型在sap裡都會通過轉換函式存為 'YYYYMMDD'格式.
Most of the times both type 'D' and 'DATS' behaves similarly except when they are output without any overriding additions. In such cases a 'DATS' type variable will be output with separators as specified in the "Date Format Settings" while a type 'd' variable will be output without separators.

輸出格式:輸出格式可以有三種方法設定:

1. 使用者設定 - Transaction SU3
a. 設定使用者參數
2. 本地/國家格式日期設定 - Transaction OY01
a. 先使用SET COUNTRY <xx> or SET LOCALE COUNTRY <xx>命令, 在調用輸出顯示.
3. 直接使用 "WRITE' 的格式
a. DD/MM/YY
b. MM/DD/YY
c. DD/MM/YYYY
d. MM/DD/YYYY
e. DDMMYY
f. MMDDYY
g. YYMMDD
h. USING EDIT MASK '==SDATE' -value checked for validity
i. USING EDIT MASK '==LDATE' -value checked for validity

2.時間(Time)

在sap裡Time類型通過隱含的轉換函式變為CHARACTER*6.
Elementary data type = T 內部長度和 輸出長度都等於 6
System data type = TIMS 內部長度 =6  輸出長度都等於= 8
所有的時間類型在sap裡都會通過轉換函式存為 'HHMMSS'格式.
Most of the times both type 'T' and 'TIMS' behaves similarly except when they are output without any overriding additions. In such cases a 'TIMS' type variable will be output with separators as specified (HH:MM:SS) while a type 'T' variable will be output without separators.

Working with Timestamp
An extension of the DATE data type that can store date and time data (including fractional seconds).

The ABAP Dictionary contains the data elements TIMESTAMP, TIMESTAMPL,

TIMESTAMP = P(8) Decimal 0
TIMESTAMPL = P(11) Decimal 7 ( decimal for fraction of second)

Commands
GET TIME: Places the current time in the system field SY-UZEIT. At the same time, SY-DATUM is set, and the system fields for the local time zone (SY-TIMLO,SY-DATLO, and SY-ZONLO) are refreshed.

GET TIME STAMP FIELD <F> Returns the timestamp in short or long form. The short form contains the current date and time; the long form also contains seven decimal places for fractions of a second, making the timestamp accurate to within 100 nanoseconds.

Time Zone
the world is divided into 24 time zones spaced at intervals of 15 degrees in longitude. The zones start at 0 with Greenwich. Within each time zone, the hour and minute of the day is defined to be the same. Time zones are usually specified by the number of hours they differ from GMT

TTZCU Customizing time zones table.

DST : Daylight Saving Time gives us the opportunity to enjoy sunny summer evenings by moving our clocks an hour forward in the spring.

Note :
Simple write statement is not going to put Timestamp in the desired output format. One has to specify a TIME ZONE for output formatting.

Transaction STZBD維護時區.
1. TTZZ : Time zones
2. TTZR : Time zone rules
3. TTZD : Summer time rules (Daylight saving).
4. TTZDF : Summer time rules (fixed annual dates)
5. TTZDV : Summer time rules (variable dates)

日期時間相關的系統變數
1. SY-TZONE Date and time, time difference from Greenwich Mean Time.
2. SY-DATUM Date and time, current (application server) date.
3. SY-UZEIT Date and time, current application server time.
4. SY-ZONLO Date and time, time zone of user.
5. SY-DATLO Date and time, local date of user.
6. SY-TIMLO Date and time, local time for user.

Time Stamp轉換
CONVERT TIME STAMP tst
TIME ZONE tz
INTO DATE d
TIME t [DAYLIGHT SAVING TIME dst].

CONVERT DATE d
TIME t [DAYLIGHT SAVING TIME dst]
INTO TIME STAMP tst
TIME ZONE tz.

The time stamp tst is always UTC time while d and t are always based on the time zone tz.The system always converts using the difference between the timezone tz and UTC time.

This implies that if you want to convert between non-UTC time zones then you can use the above statements in conjunction, First convert date & time in time zone 1 into UTC time stamp and then convert the UTC time stamp into date & time in time zone 2.  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.