My cshtml page contains the following code for DateTime
, which is some server time fetched from sql.
<tbody>
@{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.someDate)
</td>
The type of the someDate
property is DateTime
. I would like to show the time in respect to client/browser time zone, preferably using JavaSscript. What is the simples way of doing this? I looked at various similar answers but none using Html.DisplayFor
and JavaScript. I tried to use this code, but it doesn't work:
@(Html.DisplayFor(modelItem => item.someDate)).toLocaleString();
or
var localDateTime = new Date(item.someDate).toLocaleString();
@Html.DisplayFor(localDateTime )
The above may require template that I am not comfortable with as it is giving error.