This Way:
You have to enter the time like this 01:12 AM. Make sure if the time is below 10 the you have to enter the time in TextBox with the above format. If time does not match with current time then it will show the error message.
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtTime" runat="server" />
<asp:Button ID="Button1" Text="Get StartEnd Time" OnClick="StartEndTime" runat="server" /><br />
Start Time
<asp:Label ID="lblStartTime" Text="" runat="server" /><br />
<br />
End time
<asp:Label ID="lblEndTime" Text="" runat="server" />
</div>
</form>
C#:
protected void StartEndTime(object sender, EventArgs e)
{
string time = this.txtTime.Text.Trim();
string timeAmPm = time.Remove(0, 6);
string currentTime = DateTime.Now.ToString("HH:MM tt");
string currentTimeAPm = time.Remove(0, 6);
if (time.Substring(0, 2) == currentTime.Substring(0, 2) && timeAmPm == currentTimeAPm)
{
if (time.Substring(0, 2) == "12")
{
this.lblStartTime.Text = "12" + timeAmPm;
this.lblEndTime.Text = "01" + timeAmPm;
}
else
{
this.lblStartTime.Text = time.Substring(0, 2) + timeAmPm;
this.lblEndTime.Text = (int.Parse(time.Substring(0, 2)) + 1).ToString() + timeAmPm;
}
}
else
{
Response.Write("Does Not match with Current Time");
}
}
Image: