I am trying to learn c#, and have a VERY simple question. How do you display the current date inside of a td tag, also how do you display the current time inside a td tag?
Thanks.
Printable View
I am trying to learn c#, and have a VERY simple question. How do you display the current date inside of a td tag, also how do you display the current time inside a td tag?
Thanks.
You can get the current datetime with DateTime.Now, and the ToString() method accepts many different format patterns to display date and time pretty much as many ways as you can think of:
Code:<table>
<tr>
<td><%= DateTime.Now.ToString("HH:mm MM/dd/yyyy") %></td>
</tr>
</table>
It worked, although I am confused. If this is c#, where is the ;?
It's just the way those tags work. You're not sticking a line of code in there, it's an expression that must evaluate to a value. This line failsbecause Response.Write("Hello World") does not evaluate to a value. This line also fails:PHP Code:<%= Response.Write("Hello World") %>
because a semi-colon is missing(assuming you declared C# to be the language for the page). This line worksPHP Code:<% Response.Write("Hello World") %>
Not sure if this made it clearer or cloudier for ya, maybe someone else has a better explanation.PHP Code:<% Response.Write("Hello World"); %>