此方法用於將當前DateTime對象的值轉換為其等效的長時間字符串表示形式。
用法: public string ToLongTimeString ();
返回值:此方法返回一個字符串,其中包含當前DateTime對象的長時間字符串表示形式。
以下示例程序旨在說明DateTime.ToLongTimeString()方法的使用:
示例1:
// C# program to demonstrate the
// DateTime.ToLongTimeString()
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// creating object of DateTime
DateTime date = new DateTime(2011, 1,
1, 4, 0, 15);
// Converting the value of the
// current DateTime object to
// its equivalent long time
// string representation.
// using ToLongTimeString() method;
string value = date.ToLongTimeString();
// Display the time
Console.WriteLine("String representation of"+
" time is {0}", value);
}
}
輸出:
String representation of time is 04:00:15
示例2:
// C# program to demonstrate the
// DateTime.ToLongTimeString()
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// creating object of DateTime
DateTime date = DateTime.Now;
// Converting the value of the
// current DateTime object to
// its equivalent long time
// string representation.
// using ToLongTimeString() method;
string value = date.ToLongTimeString();
// Display the time
Console.WriteLine("String representation "+
"of time is {0}", value);
}
}
輸出:
String representation of time is 05:30:08
參考:
- https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tolongtimestring?view=netframework-4.7.2
相關用法
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 DateTime.ToLongTimeString() Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。