📜  C#中的DateTime.ToLongDateString()方法

📅  最后修改于: 2021-05-29 14:38:49             🧑  作者: Mango

此方法用于将当前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/zh-cn/dotnet/api/system.datetime.tolongdatestring?view=netframework-4.7.2