The code in question is below:
public static string ChangePersianDate(DateTime dateTime)
{
System.Globalization.GregorianCalendar PC = new System.Globa
You can test it in this way
Console.WriteLine(DateTime.Now.ToString("tt "));
The output will be like this:
AM
or
PM
If you want to add time to LongDateString Date, you can format it this way:
DateTime date = DateTime.Now;
string formattedDate = date.ToLongDateString();
string formattedTime = date.ToShortTimeString();
Label1.Text = "New Formatted Date: " + formattedDate + " " + formattedTime;
Output:
New Formatted Date: Monday, January 1, 1900 8:53 PM
Something like bool isPM = GetHour() > 11
. But if you want to format a date to a string, you shouldn't need to do this yourself. Use the date formatting functions for that.
its pretty simple
Date someDate = new DateTime();
string timeOfDay = someDate.ToString("hh:mm tt");
// hh - shows hour and mm - shows minute - tt - shows AM or PM
How about:
dateTime.ToString("tt", CultureInfo.InvariantCulture);
string AM_PM = string.Format("{0:hh:mm:ss tt}", DateTime.Now).Split(new char[]{' '})[1];