0

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.

jE ccA
  • 21
  • 1
  • 10

2 Answers2

0
DateTime dt = DateTime.Now;
String strDate="";
strDate = dt.ToString("MM/dd/yyyy hh:mm tt"); // 08/12/2016 02:22 PM
Manish Goswami
  • 863
  • 10
  • 27
  • Sorry I'm totally new in asp.net and jScript. This kind of problem given to me by my group. Where should i use your code? – jE ccA Aug 12 '16 at 08:54
0

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>
YonF
  • 641
  • 5
  • 20
  • The time of my server will display into the client time?. – jE ccA Aug 15 '16 at 00:55
  • In fact, every time you refresh your browser, your browser will send a request to the server, and the server will generate a or find the matched html document, then send the document to the client(your browser). The browser will display the document to you after it received the document. Back to your question, `` will generate a html label tag like this:`'`, every time you refresh or request the url, you will get a new generated document with the server `DateTime.Now`. – YonF Aug 15 '16 at 02:03
  • @ty i just add a format because i only need the date to appear – jE ccA Aug 15 '16 at 02:10