Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to provide the date as filename using javascript?

i have written some code in javascript, and i want to use today's date as my file name, even i tried below code but it wont work for me.

filename=${`any_name_${new Date().toJSON().slice(0,10)}.zip

can anyone help me with it?

like image 943
Chetan Avatar asked Oct 17 '25 17:10

Chetan


2 Answers

You can use template literals to accomplish this:

let filename = `any_name_${(new Date().toJSON().slice(0,10))}.zip`
console.log(`Add here ${filename}`);
like image 82
ABC Avatar answered Oct 20 '25 06:10

ABC


You can use string concatenation:

var filename="any_name_" + new Date().toJSON().slice(0,10) + ".zip";
console.log(filename)

Output:

any_name_2019-04-04.zip
like image 28
glhr Avatar answered Oct 20 '25 07:10

glhr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!