Asp.NET Core User Computer Time

Ali Yılmaz 81 Reputation points
2023-11-15T06:17:46.5833333+00:00

Hello,

I want to get the user's computer time on the controller side in an asp.net core web project. How can I do that.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
3,763 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 48,556 Reputation points
    2023-11-15T16:19:55.6433333+00:00

    you use javascript to add the date to a form post.

    if the controller action is a form post, add a hidden field and set it value with javascript:

    document.getElementById("fieldId).value = (new Date()).toISOString();

    if the controller action is a get, render a sniffer html page that has a small form with the data required, the snippet above and does a:

    document.getElementsByTagName[0].submit();

    note: you could also use javascript to get the timezone.


  2. Ali Yılmaz 81 Reputation points
    2023-11-16T07:33:41.8066667+00:00

    Hi,

    Can we get the date on the user's computer this way using Javascript?

    Is this the right way to do this?

    0 comments No comments

  3. Emre ARAS 0 Reputation points
    2023-11-16T07:42:04.2466667+00:00

    In JavaScript, in order to get the current timestamp, you can use Date. now()