현재 날짜 및 시간 가져오기
date_current_datetime
함수는 현재 순간의 날짜 및 시간 값을 반환합니다. 반환되는 시간은 UTC(협정 세계시)를 기준으로 하며, 다른 함수(예: date_get_day
, date_datetime_string
등)를 사용할 때 선택한 시간대로 변환됩니다.
문법
date_current_datetime();
반환값
- 날짜 및 시간 값
예제
myhour = date_get_hour(date_current_datetime());
myday = date_get_day(date_current_datetime());
위의 코드는 로컬 변수 myhour
에 현재 시간의 시(hour)를 저장하고, myday
에 현재 날짜의 일(day)을 저장합니다. date_current_time()
함수가 UTC로 시간을 반환하더라도, date_get_hour
와 date_get_day
함수에서 얻는 값은 기본적으로 로컬 시간으로 변환됩니다(단, date_set_timezone
에서 변경하지 않는 한).
활용 예제
예제 번호 | 설명 |
---|---|
1 | 현재 날짜와 시간을 출력하는 코드 |
2 | 특정 시간대의 현재 시간을 가져오는 코드 |
3 | 현재 날짜의 요일을 출력하는 코드 |
4 | 현재 연도와 월을 가져오는 코드 |
예제 1: 현재 날짜와 시간을 출력하는 코드
current_datetime = date_current_datetime();
show_message("현재 날짜 및 시간: " + string(current_datetime));
예제 2: 특정 시간대의 현재 시간을 가져오는 코드
date_set_timezone("Asia/Seoul");
current_datetime = date_current_datetime();
show_message("서울의 현재 날짜 및 시간: " + string(current_datetime));
예제 3: 현재 날짜의 요일을 출력하는 코드
current_day = date_get_day(date_current_datetime());
show_message("오늘은 " + string(current_day) + "일입니다.");
예제 4: 현재 연도와 월을 가져오는 코드
current_year = date_get_year(date_current_datetime());
current_month = date_get_month(date_current_datetime());
show_message("현재 연도: " + string(current_year) + ", 현재 월: " + string(current_month));