Show current date

You can use dotnet watch and observe the result of code changes instantly on the browser!

Showing various variations of displaying date

If you experience trouble with Visual Studio extension crashing, see trouble shooting.

using expression

@page
<p>Today's date is @DateTime.Now.Date</p>

using code block with expression

@page

@{
    var today = DateTime.Now.Date.ToShortDateString();
}
<p>Today's date is @today</p>

Using function directive

@page

@{
    ShowDateBold();
}

@functions {
    private void ShowDateBold()
    {
        <strong>@DateTime.Now.ToShortDateString()</strong>
    }
}

Last updated