2014-02-10 29 views
2

我使用asp.net web表單的第一次,我試圖表現在以下形式的當前日期:週五,7月13日如何在Aspx頁面上顯示日期?

<h3>Suggested reading for <% DateTime.Now.ToString(); %></h3> 

然而,這只是顯示

Suggested reading for 

上我的頁面。

我不知道這是否會有所幫助,但這裏是周邊的一些代碼:

<%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Fake_Coupon_Site.Account.Register" %> 

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> 
    <hgroup class="title"> 
     <h1><%: Title %>.</h1> 
     <h2>Use the form below to create a new account.</h2> 
     <h3>Suggested reading for <% DateTime.Now.ToString(); %></h3> 
    </hgroup> 

回答

7

嘗試

<h3>Suggested reading for <%= DateTime.Now.ToString("dddd, MMMM dd") %></h3> 
+0

你的答案的作品!但爲什麼在'<% %>'中有'='? – ArmorCode

+0

這只是一個不同類型的代碼塊,'<%= ... %>'與編寫'<%Response.Write(...)%>'相同,下面是關於不同代碼塊的更多信息以及它們的作用:http: //support.microsoft.com/kb/976112 –

+0

您也可能希望將文化添加到ToString方法。 – Ruruboy