UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Get current date- Asp.net - C#

Demo and code for how to get current date in Asp.net -C#

by Athil


Posted on 27 Jul 2018 Category: Asp.net Views: 37

Edited on 13 Jul 2019


Here I am going to show how to get the current date in Asp.net.

DEMO

C# code


///Get server system date
 protected void Button1_Click(object sender, EventArgs e)
 {
      TextBox1.Text = DateTime.Now.ToShortDateString();
 }
/// get UTC Date
 protected void Button2_Click(object sender, EventArgs e)
 {
      TextBox1.Text = DateTime.UtcNow.ToShortDateString();
 }

Full Demo code

ASPX

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo for how to get current date and UTC in asp.net - c#</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Demo for how to get current date and UTC in asp.net - c# </h1>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br/>
        <asp:Button ID="Button1" runat="server" Text="current date" OnClick="Button1_Click" />
        <br />
        <asp:Button ID="Button2" runat="server" Text="current UTC date" OnClick="Button2_Click" />

    </div>
     
    </form>
</body>
</html>

C# Code


///Get server system date
 protected void Button1_Click(object sender, EventArgs e)
 {
      TextBox1.Text = DateTime.Now.ToShortDateString();
 }
/// get UTC Date
 protected void Button2_Click(object sender, EventArgs e)
 {
      TextBox1.Text = DateTime.UtcNow.ToShortDateString();
 }

 



Leave a Comment: