简体   繁体   中英

String is not recognized as datetime format asp.net?

 objRA_Campaigns.StartDate = DateTime.ParseExact(tbAgentsAgentComparisonByQuestionaireFrom.Text, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);

asp.net calendar extender

<td style="padding-top: 5px; *padding-top: 3px; padding-left: 2px;" valign="middle">
                                <asp:TextBox ID="tbAgentsAgentComparisonByQuestionaireFrom" runat="server" CssClass="textBoxStyle"
                                    meta:resourcekey="tbAgentsAgentComparisonByQuestionaireFromResource1" 
                                    Width="282px"></asp:TextBox>
                                <asp:ImageButton ID="imgDateCampaignStart" runat="server" CssClass="imgbutton" ImageUrl="~/Images/Calendar.png"
                                    meta:resourcekey="imgDateCampaignStartResource1" />
                                <cc1:CalendarExtender ID="calAgentsAgentComparisonByQuestionaireFrom" runat="server"
                                    Format="dd-MM-yyyy" PopupButtonID="imgDateCampaignStart" TargetControlID="tbAgentsAgentComparisonByQuestionaireFrom"
                                    Enabled="True">
                                </cc1:CalendarExtender>
                            </td>

Exception is string is not in date time format.

Your CalendarExtender has dd-MM-yyyy as format, and you're parsing it as yyyy/MM/dd HH:mm:ss . Both formats should match for the parse to be possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM