Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2813 Lượt xem

I need to obtain the create date of an order with the following format:

20070702 = YYYYMMDD

So far I was able to obtain the order's create date with the following code:

let order  = this.pos.get_order()

let order_date = order.creation_date

let formatted_date = order.creation_date.getFullYear() + order.creation_date.getMonth() + order.creation_date.getDate()

console.log(order_date)

console.log(formatted_date)

this outputs in the browser's console log like the following:

Fri Apr 17 2020 11:47:57 GMT-0400

2040

How do I get the date format I need?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

var formatted_date  = order.creation_date.getFullYear() + ('00' + order.creation_date.getMonth()).slice(-2) + ('00' + order.creation_date.getDay()).slice(-2)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 20
2207
1
thg 11 24
1384
4
thg 10 24
3618
0
thg 10 22
5125
0
thg 9 22
38