형식이 지정된 표현식을 날짜 또는 시간으로 반환합니다.
구문
FormatDateTime(Date[,NamedFormat])
인수:
주:
Settings: NamedFormat 인수의 설정은 다음과 같습니다.
vbGeneralDate: 일반 날짜 형식의 날짜를 가져오려면 값을 0으로 전달합니다.
날짜 및/또는 시간을 표시합니다. 날짜 부분이 있는 경우 해당 부분을 short형 날짜로 표시합니다. 시간 부분이 있는 경우 해당 부분을 Long형 시간으로 표시합니다. 있는 경우 두 부분이 모두 표시됩니다.
예 1:
Dim d, mytime d="12/19/2024" mytime = FormatDateTime(d,0) 'Output: 12/19/2024 12:00:00 AM d="12/19/2024 02:30 PM" mytime = FormatDateTime(d,0) 'Output: - 12/19/2024 02:30:00 PM d="14:30:10 12/19/2024" mytime = FormatDateTime(d,0) 'Output: - 12/19/2024 02:30:10 PM d="02:30 PM 12/19/2024" mytime = FormatDateTime(d,0) 'Output: - 12/19/2024 02:30:00 PM d="12/19/2024 2pm" mytime = FormatDateTime(d,0) Output: - 12/19/2024 02:00:00 PM d="2 pm" mytime = FormatDateTime(d,0) 'Output: - 12/30/1899 02:00:00 PM d="12-19-2024" mytime = FormatDateTime(d,0) 'Output: - ERROR as delimiter should be same as locale’s delimiter
vbLongDate: Long Date Pass Value 1을 가져옵니다.
컴퓨터의 지역 설정에 지정된 Long형 날짜 형식을 사용하여 날짜를 표시합니다.
주:
Long형 날짜는 영어 문자로만 내용을 표시하고 평일 구문 분석은 지원되지 않습니다.예 2:
Dim d, mytime d="12/19/2024" mytime = FormatDateTime(d,1) 'Output: 12/19/2024 12:00:00 AM d="12/19/2024 02:30 PM" mytime = FormatDateTime(d,1) 'Output: - 12/19/2024 02:30:00 PM d="14:30:10 12/19/2024" mytime = FormatDateTime(d,1) 'Output: - 12/19/2024 02:30:10 PM d="02:30 PM 12/19/2024" mytime = FormatDateTime(d,1) 'Output: - 12/19/2024 02:30:00 PM d="12/19/2024 2pm" mytime = FormatDateTime(d,1) Output: - 12/19/2024 02:00:00 PM d="2 pm" mytime = FormatDateTime(d,1) 'Output: - 12/30/1899 02:00:00 PM d="12-19-2024" mytime = FormatDateTime(d,1) 'Output: - ERROR as delimiter should be same as locale’s delimiter
vbShortDate: Short Date Pass Value 2를 가져옵니다.
컴퓨터의 지역 설정에 지정된 날짜 형식을 사용하여 날짜를 표시합니다.
예 3:
Dim d, mytime d="12/19/2024" mytime = FormatDateTime(d,2) 'Output: 12/19/2024 12:00:00 AM d="12/19/2024 02:30 PM" mytime = FormatDateTime(d,2) 'Output: - 12/19/2024 02:30:00 PM d="14:30:10 12/19/2024" mytime = FormatDateTime(d,2) 'Output: - 12/19/2024 02:30:10 PM d="02:30 PM 12/19/2024" mytime = FormatDateTime(d,2) 'Output: - 12/19/2024 02:30:00 PM d="12/19/2024 2pm" mytime = FormatDateTime(d,2) Output: - 12/19/2024 02:00:00 PM d="2 pm" mytime = FormatDateTime(d,2) 'Output: - 12/30/1899 02:00:00 PM d="12-19-2024" mytime = FormatDateTime(d,2) 'Output: - ERROR as delimiter should be same as locale’s delimiter
vbLongTime: Long Time Format Pass Value 3의 시간을 가져옵니다.
컴퓨터의 지역 설정에 지정된 시간 형식을 사용하여 시간을 표시합니다.
주:
Long형 시간은 AM 또는 PM과 같이 영문자로만 내용을 표시합니다.예 4:
Dim d, mytime d="12/19/2024" mytime = FormatDateTime(d,3) 'Output: 12/19/2024 12:00:00 AM d="12/19/2024 02:30 PM" mytime = FormatDateTime(d,3) 'Output: - 12/19/2024 02:30:00 PM d="14:30:10 12/19/2024" mytime = FormatDateTime(d,3) 'Output: - 12/19/2024 02:30:10 PM d="02:30 PM 12/19/2024" mytime = FormatDateTime(d,3) 'Output: - 12/19/2024 02:30:00 PM d="12/19/2024 2pm" mytime = FormatDateTime(d,3) Output: - 12/19/2024 02:00:00 PM d="2 pm" mytime = FormatDateTime(d,3) 'Output: - 12/30/1899 02:00:00 PM d="12-19-2024" mytime = FormatDateTime(d,3) 'Output: - ERROR as delimiter should be same as locale’s delimiter
vbShortTime: Short Time Format Pass Value 4의 시간을 가져옵니다.
시간을 24시간 형식(hh:mm)을 사용하여 표시합니다.
예 5:
Dim d, mytime d="12/19/2024" mytime = FormatDateTime(d,4) 'Output: 12/19/2024 12:00:00 AM d="12/19/2024 02:30 PM" mytime = FormatDateTime(d,4) 'Output: - 12/19/2024 02:30:00 PM d="14:30:10 12/19/2024" mytime = FormatDateTime(d,4) 'Output: - 12/19/2024 02:30:10 PM d="02:30 PM 12/19/2024" mytime = FormatDateTime(d,4) 'Output: - 12/19/2024 02:30:00 PM d="12/19/2024 2pm" mytime = FormatDateTime(d,4) Output: - 12/19/2024 02:00:00 PM d="2 pm" mytime = FormatDateTime(d,4) 'Output: - 12/30/1899 02:00:00 PM d="12-19-2024" mytime = FormatDateTime(d,4) 'Output: - ERROR as delimiter should be same as locale’s delimiter