Strings.FormatDateTime(DateTime, DateFormat) 메서드
정의
날짜/시간 값을 나타내는 문자열 식을 반환합니다.Returns a string expression representing a date/time value.
public static string FormatDateTime (DateTime Expression, Microsoft.VisualBasic.DateFormat NamedFormat = Microsoft.VisualBasic.DateFormat.GeneralDate);
static member FormatDateTime : DateTime * Microsoft.VisualBasic.DateFormat -> string
Public Function FormatDateTime (Expression As DateTime, Optional NamedFormat As DateFormat = Microsoft.VisualBasic.DateFormat.GeneralDate) As String
매개 변수
- Expression
- DateTime
필수 요소.Required. 서식을 지정할 Date
식입니다.Date
expression to be formatted.
- NamedFormat
- DateFormat
선택 사항입니다.Optional. 사용되는 날짜/시간 형식을 나타내는 숫자 값입니다.Numeric value that indicates the date/time format used. 이 인수를 생략하면 DateFormat.GeneralDate
가 사용됩니다.If omitted, DateFormat.GeneralDate
is used.
반환
날짜/시간 값을 나타내는 문자열 식입니다.A string expression representing a date/time value.
예외
NamedFormat
설정이 잘못되었습니다.NamedFormat
setting is not valid.
예제
이 예제에서는 함수를 사용 하는 방법을 보여 줍니다 FormatDateTime
.This example demonstrates the use of the FormatDateTime
function.
' English (US) format.
Dim testDate As DateTime = #3/12/1999#
' FormatDateTime returns "Friday, March 12, 1999".
' The time information is neutral (00:00:00) and therefore suppressed.
Dim testString As String = FormatDateTime(testDate, DateFormat.LongDate)
설명
Date
데이터 형식에는 항상 날짜 및 시간 정보가 포함 됩니다.The Date
data type always contains both date and time information. 형식 변환의 목적을 위해 Visual Basic은 1/1/1 (1 년 1 월 1 일)을 날짜의 중립 값으로 간주 하 고 00:00:00 (자정)을 시간에 대 한 중립 값으로 간주 합니다.For purposes of type conversion, Visual Basic considers 1/1/1 (January 1 of the year 1) to be a neutral value for the date, and 00:00:00 (midnight) to be a neutral value for the time. 값의 형식을 Date
날짜/시간 문자열로 지정 하는 경우 FormatDateTime
은 결과 문자열에 중립 값을 포함 하지 않습니다.If you format a Date
value as a date/time string, FormatDateTime
does not include neutral values in the resulting string. 예를 들어 #1/1/0001 9:30:00 #을 문자열로 변환 하는 경우 결과는 "9:30:00 AM"입니다. 날짜 정보는 표시 되지 않습니다.For example, if you convert #1/1/0001 9:30:00# to a string, the result is "9:30:00 AM"; the date information is suppressed. 그러나 날짜 정보는 여전히 원래 값에 존재 하며와 Date
같은 함수를 사용 하 여 복구할 수 있습니다 DatePart
.However, the date information is still present in the original Date
value and can be recovered with functions such as DatePart
.
참고
전달 하는 경우는 Expression
인수를 String
리터럴 FormatDateTime
에 따라 해석는 CurrentCulture 애플리케이션의 설정 합니다.If you pass the Expression
argument as a String
literal, FormatDateTime
interprets it according to the CurrentCulture setting of your application. 그러나이를 리터럴로 전달 하는 경우 Date
FormatDateTime
항상 Date
영어 (미국) 문화권에 따라 리터럴을 해석 하므로 #mm/dd/yyyy # 형식을 사용 합니다.However, if you pass it as a Date
literal, use the format #mm/dd/yyyy#, because FormatDateTime
always interprets a Date
literal according to the English (US) culture. 되기 때문에, 애플리케이션을 개발 및 사용 하 여 코딩 하는 경우 Date
하나에서 리터럴 문화권 되지만 다른 문화권을 포함 하는 플랫폼에서 실행할를 Date
리터럴 수 올바로 구문 분석 되지 않습니다.This is necessary because, if an application is developed and coded using Date
literals from one culture, but is then executed on a platform with a different culture, the Date
literals could be parsed incorrectly.
NamedFormat
인수의 설정은 다음과 같습니다.The NamedFormat
argument has the following settings.
상수Constant | 설명Description |
---|---|
DateFormat.GeneralDate |
날짜 및/또는 시간을 표시 합니다.Display a date and/or time. 날짜 부분을 짧은 날짜로 표시 합니다.Display a date part as a short date. 시간 부분이 있으면 오랜 시간으로 표시 합니다.If there is a time part, display it as a long time. 있는 경우 두 파트가 모두 표시 됩니다.If present, both parts display. |
DateFormat.LongDate |
컴퓨터의 국가별 설정에 지정 된 자세한 날짜 형식을 사용 하 여 날짜를 표시 합니다.Display a date using the long date format specified in your computer's regional settings. |
DateFormat.ShortDate |
컴퓨터의 국가별 설정에 지정 된 간단한 날짜 형식을 사용 하 여 날짜를 표시 합니다.Display a date using the short date format specified in your computer's regional settings. |
DateFormat.LongTime |
컴퓨터의 국가별 설정에 지정 된 시간 형식을 사용 하 여 시간을 표시 합니다.Display a time using the time format specified in your computer's regional settings. |
DateFormat.ShortTime |
24 시간 형식을 사용 하 여 시간을 표시 합니다 (hh: mm).Display a time using the 24-hour format (hh:mm). |
적용 대상
추가 정보
- Format(Object, String)
- FormatCurrency(Object, Int32, TriState, TriState, TriState)
- FormatNumber(Object, Int32, TriState, TriState, TriState)
- FormatPercent(Object, Int32, TriState, TriState, TriState)
- ArgumentException
- DatePart(DateInterval, DateTime, FirstDayOfWeek, FirstWeekOfYear)
- 문자열 조작 요약String Manipulation Summary