如何从时间选择器中获取价值?

时间:2014-10-20 09:30:21

标签: c# ajax

我正在使用第三部分时间选择器。时间选择器组件

<%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="cc1" %>

时间选择器背后的源代码是

<tr>
    <td align="left" class="style3">
        From Time
    </td>
    <td align="left">
        <cc1:TimeSelector ID="TimeSelector1" runat="server" Height="10px">
        </cc1:TimeSelector>
    </td>
</tr>

我想将所选时间添加到数据库中。如何将所选时间设置为字符串或如何检索所选时间?我只是试图获得像

这样的价值
string time=TimeSelector1.SelectedTimeFormat.ToString()

但它不起作用。我有一个名为master的课,我这样做:

mas.leaveapply(ddcode.SelectedItem.Text, 
               txtname.Text, 
               TimeSelector1.SelectedTimeFormat.ToString());

1 个答案:

答案 0 :(得分:1)

上述问题的答案是

protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {


            DateTime time1 = DateTime.Parse(string.Format("{0:00}:{1:00}", TimeSelector1.Hour, TimeSelector1.Minute,TimeSelector1.AmPm));
            DateTime time2 = DateTime.Parse(string.Format("{0:00}:{1:00}", TimeSelector2.Hour, TimeSelector2.Minute, TimeSelector2.AmPm));


            mas.leaveapply(time1.ToShortTimeString(),time2.ToShortTimeString());
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('You Have Succesfully Applied For Leave ..!!');", true);

        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }

显示时间如“10:05 PM / AM”(小时,分钟,上午/下午)