jquery - Convert string to time JavaScript (h:m) -
my friend , doing school project; task make room-reservation-site. our first year trying javascript, , want string formatted time (h:m). user of our room-reservation-site can choose time of day he/she wants room, , output is: h:m (24hour-clock:minutes). example 12:15.
therefor question is: there possible convert string (h:m) time, , check if user typed more 30minutes of booking-time? can example say:
if(start_of_reservation < start_of_reservation(+30minutes)){ alert("you need book room atleast 30minutes"); } else if(start_of_reservation > start_of_reservation(+6hours)){ alert("you can't book room longer 6 hours"); } else { // moving on.. }
var year = '2013'; var month = '04'; var day = '18'; var hour = '12'; var min = '35'; var reserv = new date(year,month,day,hour,min) console.log(reserv);
those year, month , day values might want fetch yourselves checking current date. purely show how convert string date.
use reserv.gettime()
convert milliseconds time , being able compare 2 times;
reserv.gettime() - reserv2.gettime()
for more information, check mdn.
Comments
Post a Comment