Mrunal Shidurkar
Mrunal Shidurkar

Reputation: 317

How to compare date with sever date?

I am working on online quiz so for main quiz questions i want to add on condition that checks users system date time and server date time if it match then quiz should be start, can anyone know how to do this. please response if anyone knows about it

Upvotes: 1

Views: 116

Answers (2)

Panda Zhang
Panda Zhang

Reputation: 483

Actually, as you are doing a web application, so the DateTime.Now in your back-end code is already the DateTime of server. So the problem now is how to get the datetime of client pc.

What I can come out with at the moment is :

  1. Create hidden filed in your page

    Assume you are using ASP.NET, you can just give your input control a runat="server" attribute like any other server side control.

  2. Before you submit the quiz, update the filed using js

  3. The server can then read it when the form posts back.

  4. Compare the time with your server time to do any logic you want

Upvotes: 1

Snooops
Snooops

Reputation: 31

There you go to catch the client date. Javascript Date Localization

You can use this and pull this information via ajax to your server and validate it.

Upvotes: 1

Related Questions