Hour from DateTime? in 24 hours format

前端 未结 5 746
迷失自我
迷失自我 2020-12-01 03:57

So i have this DateTime? and what i want to do is to obtain the hour but show it in 24 hours format.
For example:
If the hour is 2:20:23 p.m. i want to convert it to

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 04:48

    Try this:

    //String.Format("{0:HH:mm}", dt);  // where dt is a DateTime variable
    
    public static string FormatearHoraA24(DateTime? fechaHora)
    {
        if (!fechaHora.HasValue)
            return "";
    
        return retornar = String.Format("{0:HH:mm}", (DateTime)fechaHora);
    }
    

提交回复
热议问题