javascriptasp.netdateasp.net-mvc-3clock-synchronization

how to get the date and time in from PC2 to PC1?


Hello I'm having trouble how can I overcome this problem I search some articles but some examples provided is in PHP. As my title above how can I get the Date and Time from the PC2(Server side where I publish my project) (example of date and time is 8/12/2016 4:40 PM) -- and the current time of my PC1(client side who use the project) (example of date and time is 8/10/2016 5:00). What I want is, I want to display the server side time into one of my label in a view. And even I manipulate / change the PC1 date and time setting the label don't affect / change because it came from the PC2 time. I tried to use Datetime.now() and try to change the setting time from the PC1 and my label date also change after I refresh the page.


Solution

  • It seems you are working with Asp.net-Mvc, you want to display your server time to client browser. If you are using Razor template engineer, Try this please:

    <div>@Html.Label(DateTime.Now.ToString())</div>
    

    Or like this:

    <label for="">@DateTime.Now.ToString()</label>