此方法用於將當前DateTime對象的值轉換為其等效的長日期字符串表示形式。
用法: public string ToLongDateString ();
返回值:此方法返回一個字符串,其中包含當前DateTime對象的長日期字符串表示形式。
以下示例程序旨在說明DateTime.ToLongDateString()方法的使用:
示例1:
// C# program to demonstrate the
// DateTime.ToLongDateString()
// 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 date
// string representation.
// using ToLongDateString() method;
string value = date.ToLongDateString();
// Display the date
Console.WriteLine("String representation"+
" of date is {0}", value);
}
}
輸出:
String representation of date is Saturday, 01 January 2011
示例2:
// C# program to demonstrate the
// DateTime.ToLongDateString()
// 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 date
// string representation.
// using ToLongDateString() method;
string value = date.ToLongDateString();
// Display the date
Console.WriteLine("String representation "+
"of date is {0}", value);
}
}
輸出:
String representation of date is Monday, 11 February 2019
參考:
- https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tolongdatestring?view=netframework-4.7.2
相關用法
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 DateTime.ToLongDateString() Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。