Open In App

DateTime.ToLongTimeString() Method in C#

Last Updated : 11 Feb, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

This method is used to convert the value of the current DateTime object to its equivalent long time string representation.

Syntax: public string ToLongTimeString ();

Return Value: This method returns a string that contains the long time string representation of the current DateTime object.

Below programs illustrate the use of DateTime.ToLongTimeString() Method:

Example 1:




// C# program to demonstrate the
// DateTime.ToLongTimeString()
// 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 time 
        // string representation.
        // using ToLongTimeString() method;
        string value = date.ToLongTimeString();
  
        // Display the time
        Console.WriteLine("String representation of"+
                              " time is {0}", value);
    }
}


Output:

String representation of time is 04:00:15

Example 2:




// C# program to demonstrate the
// DateTime.ToLongTimeString()
// 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 time 
        // string representation.
        // using ToLongTimeString() method;
        string value = date.ToLongTimeString();
  
        // Display the time
        Console.WriteLine("String representation "+
                          "of time is {0}", value);
    }
}


Output:

String representation of time is 05:30:08

Reference:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads