Strings.FormatDateTime(DateTime, DateFormat) Yöntem

Tanım

Tarih/saat değerini gösteren bir dize ifadesi döndürür.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

Parametreler

Expression
DateTime

Gereklidir.Required. Date Biçimlendirilecek ifade.Date expression to be formatted.

NamedFormat
DateFormat

İsteğe bağlı.Optional. Kullanılan tarih/saat biçimini gösteren sayısal değer.Numeric value that indicates the date/time format used. Atlanırsa, DateFormat.GeneralDate kullanılır.If omitted, DateFormat.GeneralDate is used.

Döndürülenler

String

Bir tarih/saat değerini temsil eden bir dize ifadesi.A string expression representing a date/time value.

Özel durumlar

NamedFormat ayar geçerli değil.NamedFormat setting is not valid.

Örnekler

Bu örnek, işlevinin kullanımını gösterir 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)

Açıklamalar

DateVeri türü her zaman hem tarih hem de saat bilgilerini içerir.The Date data type always contains both date and time information. Tür dönüştürme amaçları doğrultusunda Visual Basic, 1/1/1 (yıl 1 ' den 1 ' de) tarih için nötr bir değer ve 00:00:00 (gece yarısı) zaman için nötr bir değer olacak şekilde değerlendirir.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. Bir Date değeri tarih/saat dizesi olarak biçimlendirirseniz, FormatDateTime sonuç dizesinde nötr değerler içermez.If you format a Date value as a date/time string, FormatDateTime does not include neutral values in the resulting string. Örneğin, #1/1/0001 9:30:00 # öğesini bir dizeye dönüştürürseniz, sonuç "9:30:00" olur; tarih bilgileri bastırılır.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. Ancak, tarih bilgileri özgün değerde hala bulunur Date ve gibi işlevlerle kurtarılabilir DatePart .However, the date information is still present in the original Date value and can be recovered with functions such as DatePart.

Not

ExpressionBağımsız değişkeni bir sabit değer olarak geçirirseniz String , FormatDateTime bunu CurrentCulture uygulamanızın ayarına göre yorumlar.If you pass the Expression argument as a String literal, FormatDateTime interprets it according to the CurrentCulture setting of your application. Ancak, bunu bir sabit değer olarak geçirirseniz, Date #mm/dd/yyyy # biçimini kullanın, çünkü FormatDateTime her zaman bir Date sabit DEĞERI İngilizce (ABD) kültürüne göre yorumlar.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. Bu gereklidir çünkü bir uygulama Date bir kültürden değişmez değerler kullanılarak geliştirilir ve kodluysa, ancak daha sonra farklı bir kültüre sahip bir platformda yürütülürse, Date değişmez değerler yanlış ayrıştırılabiliyordu.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.

NamedFormatBağımsız değişkeni aşağıdaki ayarlara sahiptir.The NamedFormat argument has the following settings.

SabitConstant DescriptionDescription
DateFormat.GeneralDate Bir tarih ve/veya saat görüntüleyin.Display a date and/or time. Tarih bölümünü kısa tarih olarak görüntüleyin.Display a date part as a short date. Bir zaman parçası varsa, uzun bir süre görüntüleyin.If there is a time part, display it as a long time. Varsa, her iki parça de görüntülenir.If present, both parts display.
DateFormat.LongDate Bilgisayarınızın bölgesel ayarlarında belirtilen uzun tarih biçimini kullanarak bir tarih görüntüler.Display a date using the long date format specified in your computer's regional settings.
DateFormat.ShortDate Bilgisayarınızın bölgesel ayarlarında belirtilen kısa tarih biçimini kullanarak bir tarih görüntüler.Display a date using the short date format specified in your computer's regional settings.
DateFormat.LongTime Bilgisayarınızın bölgesel ayarlarında belirtilen saat biçimini kullanarak bir saat görüntüler.Display a time using the time format specified in your computer's regional settings.
DateFormat.ShortTime 24 saat biçimini (SS: DD) kullanarak bir saat görüntüleyin.Display a time using the 24-hour format (hh:mm).

Şunlara uygulanır

Ayrıca bkz.