将用户的24h输入转换为12h [英] Convert a user's 24h input to 12h

查看:578
本文介绍了将用户的24h输入转换为12h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,出于某种原因,这出现了一个错误消息,指出无重载for methodParseExact需要1个参数。有没有人知道我做错了什么?

  static void runTimeConverter()
{
double arrivalTime ;
arrivalTime = getArrivalTime();
string time = DateTime.ParseExact(arrivalTime).ToString(HH:mm tt);
Console.WriteLine(Equals+ time);
}

static double getArrivalTime()

{
Console.WriteLine
(输入24小时格式的时间转换为12小时);
string timeSelected = Console.ReadLine();
int timeInput = int.Parse(timeSelected);
return timeInput;
}


解决方案


method没有重载ParseExact需要1个参数。有人知道我做了什么
错了吗?


是的。 YOu不能阅读或拒绝处理编译器显示的错误信息 - 这是非常确切的错误。



您的代码:


DateTime.ParseExact(arrivalTime)


这是一个参数。编译器说这是错误的。



如果您检查文档:



http://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110 ).aspx



它显示他的方法为:

  public static DateTime ParseExact(
string s,
string format,
IFormatProvider provider

这是3个参数。你只给一个。没有变得更明显修正您的代码。


So for some reason this comes up with an error message saying that 'no overload for method'ParseExact' takes 1 argument'. Does anyone know what I've done wrong?

 static void runTimeConverter()
{   
 double arrivalTime;
 arrivalTime = getArrivalTime();
 string time = DateTime.ParseExact(arrivalTime).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;
    }

解决方案

So for some reason this comes up with an error message saying that 'no overload for method'ParseExact' takes 1 argument'. Does anyone know what I've done wrong?

Yes. YOu can not read or refuse to process the error message the compiler shows you - that is VERY exact in what is wrong.

YOur code:

DateTime.ParseExact(arrivalTime)

That is one argument. The compiler says it is wrong.

If you check the documentation:

http://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx

it shows he method as:

public static DateTime ParseExact(
    string s,
    string format,
    IFormatProvider provider
)

THat is 3 arguments. You only give one. DOes not get more obvious. Fix your code.

这篇关于将用户的24h输入转换为12h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆