DateTime.ToLongTimeString メソッド

定義

現在の DateTime オブジェクトの値を、それと等価な長い形式の時刻の文字列形式に変換します。Converts the value of the current DateTime object to its equivalent long time string representation.

public:
 System::String ^ ToLongTimeString();
public string ToLongTimeString ();
member this.ToLongTimeString : unit -> string
Public Function ToLongTimeString () As String

戻り値

String

現在の DateTime オブジェクトを長い形式の時刻で表した文字列。A string that contains the long time string representation of the current DateTime object.

ToLongTimeStringメソッドの例を次に示します。The following example demonstrates the ToLongTimeString method.

using System;
using System.Threading;
using System.Globalization;

public class Sample
{
   public static void Main()
   {
      // Create an array of culture names.
      String[] names = { "en-US", "en-GB", "fr-FR", "de-DE" };
      // Initialize a DateTime object.
      DateTime dateValue = new System.DateTime(2013, 5, 28, 10, 30, 15);

      // Iterate the array of culture names.
      foreach (var name in names) {
         // Change the culture of the current thread.
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(name);
         // Display the name of the current culture and the date.
         Console.WriteLine("Current culture: {0}", CultureInfo.CurrentCulture.Name);
         Console.WriteLine("Date: {0:G}", dateValue);

         // Display the long time pattern and the long time.
         Console.WriteLine("Long time pattern: '{0}'",
                           DateTimeFormatInfo.CurrentInfo.LongTimePattern);
         Console.WriteLine("Long time with format string:     {0:T}", dateValue);
         Console.WriteLine("Long time with ToLongTimeString:  {0}\n",
                           dateValue.ToLongTimeString());
      }
   }
}
// The example displays the following output:
//       Current culture: en-US
//       Date: 5/28/2013 10:30:15 AM
//       Long time pattern: 'h:mm:ss tt'
//       Long time with format string:     10:30:15 AM
//       Long time with ToLongTimeString:  10:30:15 AM
//
//       Current culture: en-GB
//       Date: 28/05/2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
//
//       Current culture: fr-FR
//       Date: 28/05/2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
//
//       Current culture: de-DE
//       Date: 28.05.2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
Imports System.Threading
Imports System.Globalization

Public Class Example
   Public Shared Sub Main() 
      ' Create an array of culture names.
      Dim names() As String = { "en-US", "en-GB", "fr-FR", "de-DE" }
      ' Initialize a DateTime object.
      Dim dateValue As New DateTime(2013, 5, 28, 10, 30, 15)
        
      ' Iterate the array of culture names.
      For Each name In names
         ' Change the culture of the current thread.
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(name)
         ' Display the name of the current culture and the date.
         Console.WriteLine("Current culture: {0}", CultureInfo.CurrentCulture.Name)
         Console.WriteLine("Date: {0:G}", dateValue)        

         ' Display the long time pattern and the long time.
         Console.WriteLine("Long time pattern: '{0}'", DateTimeFormatInfo.CurrentInfo.LongTimePattern)
         Console.WriteLine("Long time with format string:     {0:T}", dateValue)
         Console.WriteLine("Long time with ToLongTimeString:  {0}", dateValue.ToLongTimeString())
         Console.WriteLine()
      Next
   End Sub 
End Class 
' The example displays the following output:
'       Current culture: en-US
'       Date: 5/28/2013 10:30:15 AM
'       Long time pattern: 'h:mm:ss tt'
'       Long time with format string:     10:30:15 AM
'       Long time with ToLongTimeString:  10:30:15 AM
'       
'       Current culture: en-GB
'       Date: 28/05/2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15
'       
'       Current culture: fr-FR
'       Date: 28/05/2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15
'       
'       Current culture: de-DE
'       Date: 28.05.2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15

注釈

現在のオブジェクトの値 DateTime は、 DateTimeFormatInfo.LongTimePattern 現在のスレッドカルチャに関連付けられているプロパティによって定義されたパターンを使用して書式設定されます。The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.LongTimePattern property associated with the current thread culture. 戻り値は、メソッドで "T" 標準の日付と時刻の書式指定文字列 を指定することによって返される値と同じです ToString(String)The return value is identical to the value returned by specifying the "T" standard date and time format string with the ToString(String) method.

注意

メソッドによって返される文字列 ToLongTimeString は、カルチャに依存します。The string returned by the ToLongTimeString method is culture-sensitive. このメソッドは、現在のカルチャのプロパティで定義されているパターンを反映し DateTimeFormatInfo.LongTimePattern ます。It reflects the pattern defined by the current culture's DateTimeFormatInfo.LongTimePattern property. たとえば、en-us カルチャでは、標準の長い時刻パターンは "h:mm: ss tt" です。de 以外のカルチャでは、"HH: mm: ss" です。ja-jp カルチャでは、"H:mm: ss" になります。For example, for the en-US culture, the standard long time pattern is "h:mm:ss tt"; for the de-DE culture, it is "HH:mm:ss"; for the ja-JP culture, it is "H:mm:ss". 値は、.NET の実装とそのバージョン、オペレーティングシステムとバージョン、およびユーザーのカスタマイズによって異なる場合があることに注意してください。Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

現在のスレッド カルチャについて詳しくは、CultureInfo.CurrentCulture および Thread.CurrentCulture プロパティを参照してください。For more information about the current thread culture, see the CultureInfo.CurrentCulture and Thread.CurrentCulture properties. 書式指定文字、書式パターン、およびそれらによって生成される出力について詳しくは、「標準の日時書式指定文字列」と「カスタム日時書式指定文字列」をご覧ください。For more information about format characters, format patterns, and the output they produce, see Standard date and time format strings and Custom date and time format strings. 書式指定文字に関連付けられている書式パターンの変更について詳しくは、DateTimeFormatInfo クラスをご覧ください。For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

適用対象

こちらもご覧ください