0

I made a form asking for a date and time and returning a date and time minus a given amount of minutes

I would like to be able to display just the time –date doesn't matter in this case–, and i found out "datetime-local" doesn't work in Firefox. What would be the way to make something that works in firefox?

function finishedBake() {
  let time = new Date(document.getElementById("finishedbaking").value)
  time.setMinutes(time.getMinutes() - 634)
  var options = {
    hour: '2-digit',
    minute: '2-digit'
  };
  document.getElementById("finished").innerHTML = time.toLocaleDateString("no-NB", options)
}
<div id="bakestart">

  <div>if I want it to be finished at
    <input type="datetime-local" id="finishedbaking" required />
    <input type="submit" onclick="finishedBake()" /> i need to start at <span id="finished"></span>
  </div>

</div>
mplungjan
  • 134,906
  • 25
  • 152
  • 209
  • Search for [time picker](https://www.google.com/search?q=javascript+time+picker+site:stackoverflow.com) – mplungjan Jan 02 '21 at 19:51
  • Maybe https://developer.mozilla.org/fr/docs/Web/HTML/Element/Input/time – Thomas Jan 02 '21 at 19:56
  • Support for `time` and `datetime-local` varies a lot, so I wouldn't use them for now, not until they are better supported. Better to use some library that provides this functionality and is consistent across browsers. However, if you can't do that and the **date** part really isn't necessary, then definitely, the **time** type as suggested by @Thomas above is what I would use. – Mark Small Jan 02 '21 at 20:27
  • thanks for the suggestions. I won't be capable to use a time picker. I can make the form to use 'time', but then i don't know how to edit the function that will calculate the new time accordingly:/ – josejose Jan 02 '21 at 20:31
  • Will my old answer help https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date/60881661#60881661 ? – Tom Jan 02 '21 at 20:52
  • Tom, it would certainly help someone who understands javascript –i don't really understand it:/ – josejose Jan 03 '21 at 14:16

0 Answers0