S
S
someden2015-09-27 19:26:02
JavaScript
someden, 2015-09-27 19:26:02

How can I set the date in the format I need in the type="date" field using javascript?

There is a type="date" field

<input class="date" type="date" name="date" placeholder="__.__.____">

How can I enter the current date in the format dd.mm.yyyy when loading the page?

Tried the following code:
today = new Date();
day = today.getDate() < 10 ? '0' + today.getDate() : today.getDate();
month = today.getMonth()+1 < 10 ? '0' + (today.getMonth()+1) : (today.getMonth()+1);
date = day + '.' + month + '.' + today.getFullYear();
$('.date').val(date);

It doesn't work in chrome because it needs the format yyyy-mm-dd even though it displays the values ​​of this field in the format dd.mm.yyyy.
It turns out that you need to track the Chrome browser, for it to write the value in the format yyyy-mm-dd, and for all the rest dd.mm.yyyy?
Is there already a solution for this or some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
littleguga, 2015-09-27
@someden

Seems like it's impossible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question