相关文章推荐
慈祥的针织衫  ·  C#/.NET/.NET ...·  5 月前    · 
鬼畜的香烟  ·  vue.js ...·  2 年前    · 
打篮球的拐杖  ·  用div画横线_div ...·  2 年前    · 
精明的椅子  ·  android ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using an input for the date. How do we set the Input to display the Date Today? Thank you for your time.

                            <div class="form-group">
                                <label>Debarred</label>
                                <input v-model="form.debarred" type="date" name="debarred"
                                       placeholder="Debarred"
                                       class="form-control" :class="{ 'is-invalid': form.errors.has('debarred') }">
                                <has-error :form="form" field="debarred"></has-error>

You can update the model value form.debarred on page load like:

this.form.debarred = new Date().toLocaleDateString('en-CA');
//==> "2020-04-03" 

Now, using .toLocaleDateString('en-CA') is need here as <input type="date"> value can only accept a string representing a date in YYYY-MM-DD format, or empty.

DEMO:

const debarred = document.querySelector('[name=debarred]');
debarred.value = new Date().toLocaleDateString('en-CA');
<div class="form-group">
  <label>Debarred</label>
  <input type="date" name="debarred" placeholder="Debarred" class="form-control">
  <has-error :form="form" field="debarred"></has-error>
                Wow. Thank you!  I'm using vue.js and I placed your code in the script this.form.debarred = new Date().toLocaleDateString('en-CA'); it worked like charm.
– No One
                Apr 3, 2020 at 18:40
                Do you have a patreon? How can I remove the time for this code ```                console.log(new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toLocaleString('en-CA'));```
– No One
                Apr 3, 2020 at 20:36
                Sorry, but I will be be offline soon. Can't help at the moment. Please post a new question regarding it. I am sure someone will be glad to help. Also, post the question link here. I will try to look into it tomorrow.
– palaѕн
                Apr 3, 2020 at 20:48
                You can try this: new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toLocaleString('en-CA').split(',')[0]
– palaѕн
                Apr 4, 2020 at 6:15
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.