How to write data in the Cookie and their processing?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
18 views
Hello! wrote a script which considers + 4 days from the current date, displays the current year and month s what. The type of action ends the current date + 4 days. The question is how to record the date of the first entry the user in cookies, then add 4 days to that date , when it will take these 4 days to bring the campaign ended ?
var fourDays = 4; var currentDate = new Date(); //create a variable for the current date currentDate.setDate(currentDate.getDate() + fourDays); //add to the current date 10 days var dd = currentDate.getDate(); //get current day var mm = currentDate.getMonth() + 1; //add 1 because months are counted from 0 // translation of the month var rusMonth; if(mm == 01) { rusMonth = "Jan" } else if (mm == 02) { rusMonth = "Feb" } else if (mm == 03) { rusMonth = "Mar" } else if (mm == 04) { rusMonth = "APR" } else if (mm == 05) { rusMonth = "May" } else if (mm == 06) { rusMonth = "Jun" } else if (mm == 07) { rusMonth = "Jul" } else if (mm == 08) { rusMonth = "Aug" } else if (mm == 09) { rusMonth = "Sep" } else if (mm == 10) { rusMonth = "Oct" } else if (mm == 11) { rusMonth = "Nov" } else if (mm == 12) { rusMonth = "Dec" } var yyyy = currentDate.getFullYear(); //get year if(dd<10) { dd = '0'+ dd //in front of the day number attributed to a "0" to the number "01", "02, etc. } if(mm<10) { mm = '0'+ mm //similar situation with the number of the month } currentDate = dd + '.' + rusMonth + '.' + yyyy; //set the format and the date display order document.write("LEAVE the APPLICATION TO" + currentDate); //print the text
by | 18 views

2 Answers

0 like 0 dislike
to work with cookies you can try jquery.cookie.js
by
0 like 0 dislike
Do not have to reinvent the wheel, everything is already written before you.
\rhttps://momentjs.com/
Jquery cookie is also not necessary to use - there is an analogue in vanilla js, more lightweight and functional
\rhttps://github.com/js-cookie/js-cookie
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users