Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
DateTime.ToLongTimeString() Method in C#
The DateTime.ToLongTimeString() method in C# is used to convert the value of the current DateTime object to its equivalent long time string representation.
Syntax
Following is the syntax −
public string ToLongTimeString ();
Example
Let us now see an example to implement the DateTime.ToLongTimeString() method −
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);
}
}
Output
This will produce the following output −
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
Example
Let us now see another example to implement the DateTime.ToLongTimeString() method −
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);
}
}
Output
This will produce the following output −
Date = 11/11/2019 7:11:25 AM Long time string representation = 7:11:25 AM
Advertisements
