I have a page on my site that displays a list of members. I'm using .NET Core MVC and Razor to render my views.
I'm storing the members' registration date as UTC, and would like that date/time converted to the user's local timezone when they view the page.
I'm using javascript to do this:
<script>
function GetLocalDateTime(utcDate) {
var localDate = new Date(utcDate);
console.log(localDate.toString());
return localDate.toString();
}
</script>
....
@foreach (var member in Model.Items)
{
<tr>
...
<td>
<script>
GetLocalDateTime('@(member.CreatedDate.ToString("MM/dd/yyyy hh:mm:ss tt UTC"))');
</script>
</td>
</tr>
}
The problem is that the return value from the javascript function doesn't get displayed in my table. But the function is being called, the converted date values are logging in the console.
What am I doing wrong here?
If you want show the date,you need to update the dom rather than just return the local date
modify return localDate.toString(); to document.write( localDate.toString());
