Get system DateTime
DateTime.Now property allow us to get a System DateTime object that is set to the current date and time on this computer (web server).
this property exists in System namespace. this property return value type is System.DateTime which represent the current local date and time. after getting the current datetime object we can format the date and time to display in web page.
the following asp.net c# example code demonstrate us how can we get system date time programmatically at run time in an asp.net application.
the following asp.net c# example code demonstrate us how can we get system date time programmatically at run time in an asp.net application.
Now.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e) {
DateTime now = DateTime.Now;
Label1.Text = "System DateTime[Now]: " + now.ToString();
Label1.Text += "<br />System DateTime[ToDay]: " + now.ToLongDateString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net date time example: how to get system date time</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">asp.net example: DateTime.Now</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="PaleVioletRed"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Font-Bold="true"
Text="Get System DateTime[Now]"
ForeColor="Magenta"
/>
</div>
</form>
</body>
</html>

- How to get the number of days in a given month
- How to create a TimeSpan
- 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 get the AM PM value from 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 first day of a month using a given date
- How to get the last day of month using a given date