0

I want to convert to date to UTC due to cookie set expires date.

const date = new Date();
date.setDate(date.getDate() + 1); // 1days add
$.cookie('AA', '', {
      expires: new Date(Date.UTC(date.getFullYear(), date.getMonth(), 
      date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())),
    });

This code works well.. But, I want to know efficient and compact code! Pleae tell me the other opinions!!

zuuuuuuuu
  • 15
  • 4

1 Answers1

0

You can simply call date.getUTCDate() to get the UTC date instance. See this documentation.

So your code will be like:

const date = new Date();
date.setDate(date.getDate() + 1); // 1days add
$.cookie('AA', '', {
   expires: date.toUTCString(),
});
Imesha Sudasingha
  • 3,462
  • 1
  • 23
  • 34