DateTime.ToLongDateString() 方法(C#)
C# 中的 DateTime.ToLongDateString() 方法用于将当前 DateTime 对象的值转换为其等效的长日期字符串表示形式。
语法
以下是语法 −
public string ToLongDateString ();
示例
下面我们来看一个示例来实现 DateTime.ToLongDateString() 方法 −
using System; public class Demo { public static void Main() { DateTime d = new DateTime(2019, 10, 11, 9, 10, 45); Console.WriteLine("Date = {0}", d); string str = d.ToLongDateString(); Console.WriteLine("Long date string representation = {0}", str); } }
输出
这将产生以下输出 −
Date = 10/11/2019 9:10:45 AM Long date string representation = Friday, October 11, 2019
示例
下面我们来看另一个实现 DateTime.ToLongDateString() 方法的示例 −
using System; using System.Globalization; public class Demo { public static void Main() { DateTime d = DateTime.Now; Console.WriteLine("Date = {0}", d); Console.WriteLine("Current culture = "+CultureInfo.CurrentCulture.Name); var pattern = CultureInfo.CurrentCulture.DateTimeFormat; string str = d.ToLongDateString(); Console.WriteLine("Long date string = {0}", pattern.LongDatePattern); Console.WriteLine("Long date string representation = {0}", str); } }
输出
这将产生以下输出 −
Date = 10/16/2019 8:39:08 AM Current culture = en-US Long date string = dddd, MMMM d, yyyy Long date string representation = Wednesday, October 16, 2019
广告