var date = new Date();
var yesterday = date.setDate(date.getDate() - 1);
yesterday = date.toLocaleDateString('en-GB');
console.log(yesterday);
i want to use the date format dd/mm/yyyy
code I want the result I run in javascript : 21/03/2019
result I run in puppeteer : 3/21/2019
i don't wan't puppeteer result.
Why are the results different?
how to change puppeteer date format?
You can use replace method to switch the places of month
and date
/(\d{2})\/(\d{2})\/(\d{4})/
var date = new Date(); var yesterday = date.setDate(date.getDate() - 1); yesterday = date.toLocaleDateString('en-GB'); console.log(yesterday) console.log(yesterday.replace(/(\\d{2})\\/(\\d{2})\\/(\\d{4})/, '$2/$1/$3'));
{
format: "A4",
printBackground: true,
displayHeaderFooter: true,
headerTemplate: `<div style="font-size:7px;white-space:nowrap;margin-left:38px;">
${new Date().toDateString()}
<span style="margin-left: 10px;">Generated PDF</span>
</div>`,
margin: {
top: '38px',
right: '38px',
bottom: '38px',
left: '38px'
} }
Change the date format in your required format.
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.