0

I need to validate time field in my project (which is a jquery-datetimepicker) in such a way that it displays time only for the rest of the day.

What I mean is :

The time now is

Wed Mar 01 2017 15:25:36 GMT+0530 (India Standard Time)  

I have an hour format in my datetimepicker.

What I want is, a day has 24 hours.

So, in the datetimepicker, it must only show hours after 15 like from 16,17 and so on till 23.

Here is a fiddle :

Fiddle

My requirement is that as soon as Share button is clicked, it must detect the current time and in the datetimepicker for hours (in expiry field in the fiddle), it must show only hours left for the day and not 00:00 as it is showing now.

Can anyone help me out here ?

Ashish Bahl
  • 1,482
  • 1
  • 18
  • 27

1 Answers1

1

I have created a code that detects the remaining time left in todays date.You can use the value in your code.Fiddle

Here is the code.

showDiff();

function showDiff() {

  var date1 = new Date();
  var date2 = new Date();
  date2.setHours(23, 59, 59, 999);

  var diff = (date2 - date1) / 1000;
  var diff = Math.abs(Math.floor(diff));

  var days = Math.floor(diff / (24 * 60 * 60));
  var leftSec = diff - days * 24 * 60 * 60;

  var hrs = Math.floor(leftSec / (60 * 60));
  var leftSec = leftSec - hrs * 60 * 60;

  var min = Math.floor(leftSec / (60));
  var leftSec = leftSec - min * 60;

  document.getElementById("showTime").innerHTML = "You have " + days + " days " + hrs + " hours " + min + " minutes and " + leftSec + " seconds before death.";

  setTimeout(showDiff, 1000);
}
<div id="showTime"></div>
shubham agrawal
  • 3,435
  • 6
  • 20
  • 31