简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM