কম্পিউটার টিউটোরিয়াল

C#-এ DateTime.ToShortTimeString() মেথড

সিনট্যাক্স

public string ToShortTimeString ();

উদাহরণ

DateTime.ToShortTimeString() মেথড বাস্তবায়ন:

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.ToShortTimeString(); 
        Console.WriteLine("Short time string = {0}", pattern.ShortTimePattern); 
        Console.WriteLine("Short time string representation = {0}", str); 
    } 
}

আউটপুট

Date = 10/16/2019 8:59:23 AM Current culture = en-US Short time string = h:mm tt Short time string representation = 8:59 AM

আরেকটি উদাহরণ

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.ToShortTimeString(); 
        Console.WriteLine("Short time string representation = {0}", str); 
    } 
}

আউটপুট

Date = 11/11/2019 7:11:25 AM Short time string representation = 7:11 AM
  1. C#-এ DateTime.AddMilliseconds() মেথড

  2. C#-এ DateTime.GetHashCode() মেথড

  3. C#-এ DateTime.GetDateTimeFormats() মেথড

  4. C#-এ DateTime.ToLongTimeString() মেথড