DateTime get AM PM
datetime-am-pm.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//initialize a datetime variable with current time
DateTime now = DateTime.Now;
//get only current time from datetime object
Label1.Text = "current time with AM PM: " + now.ToLongTimeString();
Label1.Text += "<br /><br />";
//string format to get only AM PM status from datetime object
Label1.Text += "current time [only AM PM]: " + now.ToString("tt");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime am pm</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - datetime am pm
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
Font-Names="Comic Sans MS"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="get AM PM from datetime object"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to get day from a DateTime
- How to get the number of days in a given month
- How to add 1 month to a given DateTime object
- How to add weeks to a DateTime object
- How to add a TimeSpan to a DateTime object
- How to check if a DateTime is between two given dates
- How to check if a DateTime is later than another date
- How to get the month name from month number
- How to get the first day of week
- How to get two DateTime objects difference in milliseconds