C# 中的 DateTime.ToLongTimeString() 方法
C# 中的 DateTime.ToLongTimeString() 方法用于将其值转换当前 DateTime 对象的其等效的长时间字符串表示。
语法
以下是语法 −
public string ToLongTimeString ();
示例
让我们现在看一个示例来实现 DateTime.ToLongTimeString() 方法 −
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.ToLongTimeString();
Console.WriteLine("Long time string = {0}", pattern.LongTimePattern);
Console.WriteLine("Long time string representation = {0}", str);
}
}输出
这将产生以下输出 −
Date = 10/16/2019 8:41:03 AM Current culture = en-US Long time string = h:mm:ss tt Long time string representation = 8:41:03 AM
示例
让我们现在看另一个示例来实现 DateTime.ToLongTimeString() 方法 −
using System;
public class Demo {
public static void Main() {
DateTime d = new DateTime(2019, 11, 11, 7, 11, 25);
Console.WriteLine("Date = {0}", d);
string str = d.ToLongTimeString();
Console.WriteLine("Long time string representation = {0}", str);
}
}输出
这将产生以下输出 −
Date = 11/11/2019 7:11:25 AM Long time string representation = 7:11:25 AM
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP