日期时间转换和解析 [英] Datetime conversion and parsing

查看:157
本文介绍了日期时间转换和解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码提供了以下错误:输入字符串的不正确的格式

My code gives the following error: Input string was not in a correct format.

这个提示:

当将字符串转换为DateTime,解析字符串将每个变量进入DateTime对象之前采取的日期

下面是我的代码:
(编辑,只显示有问题的代码)

 string username ="aits";
 string password = "12345";
 Int32 intresortid=7;
 string strPartySurname = "Kumar"; ;
 string strPartyFirstName = "Test";
 string strPartyPrefix = "Mr & Mrs";
 Int16 intQtyAdults=1;
 Int16 intQtyTotal=1;
 string PromotionCode = "TIF";
 string flightNO = "FlighDJ76";
 string strNotes = "<nl>Provide Breakfast<nl>Honeymooners";

 try
    {

        string url = string.Format("http://localhost/insHold.asp?username={0}&password={1‌​}&intresortid={2}&strPartySurname={3}&strPartyFirstName={4}&strPartyPrefix={5}&intQtyAdults={6}&intQtyTotal={7}&dtmLine1={8:yyyy-MM-dd}&strRoomType1={9}&intRooms1={10}&intnights1={11}&strFlightNo={12}&strNotes={13}&strBookingCode={14}&strPromotionCode={15}", username, password, intresortid, strPartySurname, strPartyFirstName, strPartyPrefix, intQtyAdults, intQtyTotal, CheckInDate, BBRoom, RoomQty, NoofNights, flightNO, strNotes, ResBookingID, PromotionCode);                                                                                                                                                                                                                                                        
        WebRequest request = HttpWebRequest.Create(url);
        WebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string urlText = reader.ReadToEnd();
        bookid = Convert.ToInt16(urlText);
    }
    catch (System.ApplicationException ex)
    {
        throw ex;
    }



我不知道如何纠正这是我的DateTime值:CheckInDate是已经类型过时了。

I don't know how to correct this as my DateTime value: CheckInDate is already of type date.

有人可以告诉我怎么解决这个问题或点我在正确的方向。

Can somebody please tell me how to fix this or point me in the right direction.

推荐答案

我刚刚改写的格式字符串,并将其解决问题。研究发现,改写{}大括号解决它。请您尝试一下。

I just rewrite the format string and it resolves the issue. Found that rewriting { } braces resolved it. Please try it.

这篇关于日期时间转换和解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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