Q: How to format date in javascript I am trying to add time in my code below.
Is it possible to display the time in a new line? I am going to display it in a table row.


document.getElementById("date").value = new Date().toJSON().slice(0,10);
<label>Arr_date:</label>
<input type="date" id="date" name="Arr_date">



A: Hi can you please elaborate more on this. My understanding is that you are looking for something like this.
Tuesday

12

March

9999
If you are talking about having a new line between the 2 elements, then I suggest you use a  tag


<label>Arr_date:</label>
<br />
<input type="date" id="date" name="Arr_date">



A: Use toTimeString():
new Date().toTimeString()

outputs something like this:
02:35:00 GMT+0200 (...)
We need hours and minutes (first five signs 02:35 -> slice(0,5)):
new Date().toTimeString().slice(0,5);

HTML:
<label>Arr_time:</label>
<input type="time" id="time" name="Arr_date"/>

JS:
document.getElementById("time").value = new Date().toTimeString().slice(0,5);

http://jsfiddle.net/w6dw8urp/
And the dates in a table:
HTML:
<table>
    <tr>
        <td><label>Arr_date:</label></td>
        <td><input type="date" id="date" name="Arr_date"/></td>
    </tr>
    <tr>
        <td><label>Arr_time:</label></td>
        <td><input type="time" id="time" name="Arr_time"/></td>
    </tr>
</table>

http://jsfiddle.net/w6dw8urp/1/
