C# এ DateTime.ToShortTimeString() পদ্ধতিটি বর্তমান DateTime অবজেক্টের মানকে এর সমতুল্য স্বল্প সময়ের স্ট্রিং উপস্থাপনায় রূপান্তর করতে ব্যবহৃত হয়।
সিনট্যাক্স
নিচের সিনট্যাক্স −
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
উদাহরণ
এখন DateTime.ToShortTimeString() পদ্ধতি প্রয়োগ করার জন্য আরেকটি উদাহরণ দেখা যাক -
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