10 examples of 'how to set current date in input type date in html' in JavaScript

Every line of 'how to set current date in input type date in html' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
77setInputText(date) {
78 let month = (date.getMonth() + 1).toString();
79 if (month.length < 2) {
80 month = `0${month}`;
81 }
82 let day = (date.getDate()).toString();
83 if (day.length < 2) {
84 day = `0${day}`;
85 }
86 this.inputText = `${date.getFullYear()}/${month}/${day}`;
87}
127function updateDate() {
128 var unix = parseDateString($("#input").val());
129 $('#unix').text(unix);
130 if(unix!==null) {
131 var date = new Date(unix*1000);
132 $('#text').text(date.toString());
133 } else {
134 $('#text').text('');
135 }
136}
52function update_date(value) {
53 if (document.getElementById("date") == null)
54 return;
55 document.getElementById("date").value = value;
56}
56function setDatetime(fieldname){
57 var d = new Date();
58 $('input[name="'+fieldname+'"]').val(("0"+ d.getHours()).slice(-2) + ":" + ("0"+ d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2));
59 return false;
60}
66function getCurrentDate() {
67 date = $("#date-picker").val();
68 time = $("#spinner").val();
69 millis = Date.parse(date + " " + time + " GMT");
70 return new Date(millis)
71}
1export function inputFormattedDate(type: string, value: any) {
2 if (value) {
3 const strDate = (value instanceof Date) ? value.toISOString() : value;
4 if (type === 'datetime-local') {
5 return strDate.slice(0, 16);
6 } else if (type === 'date') {
7 return strDate.slice(0, 10);
8 } else if (type === 'month') {
9 return strDate.slice(0, 7);
10 }
11 }
12 return value;
13}
3function updateDate() {
4 var now = new Date();
5 document.getElementById("date-output").innerHTML = dateFormat(now, "ddd d mmm");
6}
433function onChangeDate() {
434
435 var urllocation = '';
436 var fromdate = $("#fromDate").val();
437 var todate = $("#endDate").val();
438
439
440 var tilldate = '2013-01-01T00:00:00Z';
441 var currentdate = new Date();
442 var today = currentdate.getFullYear() + "-" + (currentdate.getMonth() + 1) + "-" + currentdate.getDate();
443
444
445
446 if (fromdate != "" && todate != "" && fromdate != "yyyy-dd-mmT00:00:00Z" && todate != "yyyy-dd-mmT00:00:00Z") {
447 if ((Date.parse(todate) < Date.parse(fromdate))) {
448
449 $("#endDate").val('');
450
451 document.getElementById("errorMsg").style.display = 'block';
452
453 }
454 else {
455 document.getElementById("errorMsg").style.display = 'none';
456 urllocation = window.location.href + "&fq=created_at:[" + fromdate + 'T00:00:00Z' + ' TO ' + todate + 'T23:59:59Z' + "]&start=0";
457 commondatefilter(urllocation);
458 }
459
460
461 }
462
463 if (fromdate == "" && todate == "") {
464
465 urllocation = window.location.href + "&fq=created_at:&start=0";
466 commondatefilter(urllocation);
467 }
468 if (fromdate != "" && todate == "") {
469
470 urllocation = window.location.href + "&fq=created_at:[" + fromdate + 'T00:00:00Z' + ' TO ' + today + 'T23:59:59Z' + "]&start=0";
471 commondatefilter(urllocation);
472
473 }
474 if (todate != "" && fromdate == "") {
475
476 var urllocation = window.location.href + "&fq=created_at:[" + tilldate + ' TO ' + todate + 'T23:59:59Z' + "]&start=0";
477 commondatefilter(urllocation);
478
479 }
480
481
482};
20getFieldValue() {
21 let days = this.refs.days.val()
22 let months = this.refs.months.val() - 1
23 let years = this.refs.years.val()
24 let date = new window.Date(years, months, days)
25 return date.toISOString()
26}
50function update_value() {
51 $input.val($date.val() + " " + $time.val());
52}

Related snippets