小编典典

如何从 DateTime 获取 AM/PM 值?

all

有问题的代码如下:

public static string ChangePersianDate(DateTime dateTime)
{
    System.Globalization.GregorianCalendar PC = new System.Globalization.GregorianCalendar();
    PC.CalendarType = System.Globalization.GregorianCalendarTypes.USEnglish;
    return
    PC.GetYear(dateTime).ToString()
    + "/"
    + PC.GetMonth(dateTime).ToString()
    + "/"
    + PC.GetDayOfMonth(dateTime).ToString()
    + ""
    + PC.GetHour(dateTime).ToString()
    + ":"
    + PC.GetMinute(dateTime).ToString()
    + ":"
    + PC.GetSecond(dateTime).ToString()
    + " "
    ????????????????
}

如何从dateTime值中获取 AM/PM?


阅读 75

收藏
2022-05-29

共1个答案

小编典典

怎么样:

dateTime.ToString("tt", CultureInfo.InvariantCulture);
2022-05-29