-4

Having trouble taking a time entered into a text box in html5 and writing a javascript function that will make sure the time entered is no less than 30 minutes from the present time. Mainly how to get the current date is my biggest concern. Would it be as simple as a date.now() and then adding 30 minutes to that?

StevieP
  • 131
  • 1
  • 14
  • If you're willing to use a library please consider: http://momentjs.com/ – David Tansey Mar 17 '15 at 22:23
  • What do you mean you can't find anything on time or date? There is a lot of help out there for time and date using JavaScript. Just look at w3schools http://www.w3schools.com/jsref/jsref_obj_date.asp –  Mar 17 '15 at 22:25
  • If you're willing to find something consider [Google](https://www.google.nl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=javascript%20date%20time) – Jonathan Mar 17 '15 at 22:25
  • What about Date.parse() to parse the input string into a date object and then comparing to the current time? Check this existing post: http://stackoverflow.com/questions/6212305/how-can-i-compare-two-time-strings-in-the-format-hhmmss – lintmouse Mar 17 '15 at 22:25
  • 2
    "Can't find anything on time or date functions for javascript". I find that hard to believe. What did you search for? I'll suggest [MDN as a good source](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). – Heretic Monkey Mar 17 '15 at 22:25
  • Trying not to use libraries and more of less how to get the current date and then add 30 minutes to it to verify. – StevieP Mar 17 '15 at 22:26
  • Useless? Well if that Google query wasn't what you were looking for I'm not sure you'll find much help here. – Jonathan Mar 17 '15 at 22:28
  • That google query, which I've been searching through all afternoon, showed me simply how to get the current date. I get that. What I don't get is to take a string time entered by the user and to treat that string as a time and compare it to 30 minutes. – StevieP Mar 17 '15 at 22:41

1 Answers1

0

I recently used moment.js for a project.. Has some really nice Time methods...

//// get today right now
var now = ( new Date() );
/// to see methods that a javascript date object contains try listing them
console.log( Object.keys(  now  )  );

give moment.js a google, makes finding differences between 2 dates easy..

  • Trying not to use any libraries but thank you. I feel like it should be a lot simpler than its planning out to be. I've been using the first line of code to get the current date. Trying to transfer a a string input and comparing it to current date to make sure its no less than 30 minutes after the current date. – StevieP Mar 17 '15 at 22:55