在c#中将24h转换为12h(IFormatProvider故障)

时间:2014-04-16 16:25:57

标签: c#

因此,以下代码提供了Name' CultureInfo'在当前的上下文中不存在,我尝试了其他IFormatProviders,但他们没有在Visual Studio中注册。我做错了什么?

   static void runTimeConverter()
 {   
  double arrivalTime;
  arrivalTime = getArrivalTime();  
  string time = DateTime.ParseExact(arrivalTime, "HHmm", CultureInfo.CurrentCulture)
   .ToString("hh:mm tt");
  Console.WriteLine("Equals " + time);
 }

static double getArrivalTime()

   {
    Console.WriteLine
        ("Enter time in 24 hour format to convert to 12hour");
    string timeSelected = Console.ReadLine();
    int timeInput = int.Parse(timeSelected);
    return timeInput;
}

1 个答案:

答案 0 :(得分:1)

确保将其添加到文件顶部:

using System.Globalization;