简体   繁体   中英

change date format into “DD-MM-YYYY”

I used input type "date" as below,

<input type="date" class="form-control input-sm pull-right" name="order_date" placeholder="Created At"
          id="l1" [(ngModel)]="order_date">

It gives the result with "YYYY-MM-DD" format.

I need the result as "DD-MM-YYYY" with the input type of "date'.Any idea to overcome this!

Use {{date | date:'ddMMyyyy'}} {{date | date:'ddMMyyyy'}} instead of {{date | date:'dd MM yyyy'}} {{date | date:'dd MM yyyy'}}

Use:

(ngModelChange)=setDate(order_date)

And in component:

setDate(date:Date){
  payload.date = date; // to save payload 
}

\n
\n
\n
{{order_date| formatDate: order_date:'d/M/yyyy'}}
\n
\n
\n

var newDatepickerDate = new Date(23/03/1999);
var startup = newDatepickerDate.toLocaleDateString();
var datePickerdate =startup.replace(/\b(\d\/)/g,'0$1');
var i = datePickerdate;
var dayMonthYear= i.replace(/(\d\d)\/(\d\d)\/(\d{4})/, "$3-$1-$2"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM