I need to submit current date and time as a hidden field in a javascript form.
The format this needs to be in is: mm/dd/yyyy hh:mm AMorPM
I've seen many time and date functions ond code online, but not one that allows for the date and time to be posted with the form.|||I don't like to answer your question with "don't do it that way," but I think the right answer is "don't do it that way."
The time that comes from JavaScript is the time on the user's PC. Their clock might be in a different time zone than you, or it might just be plain wrong. Any hacker can send any date or time he wants, regardless of what your JavaScript code thinks it is doing. So, any time you would get from the user is not trustworthy at all. It might be 5 minutes fast, an hour slow, the wrong year, anything. It might not even be a date, since malicious users could send anything they want instead of a date.
Programmers in these situations get the date and time from the server. Every server platform (Apache, Tomcat, IIS, ASP.NET, etc.) has this capability. Just find out on the server side what time it is when the form is posted, and then you'll know when it was posted.
If you insist on doing it in JavaScript, just remember that your server-side code can get ANYTHING. Wrong dates, malicious input, whatever. The server-side software has to be ready for anything.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment