こんな感じでいかがでしょうか?
JavaScriptのendDateTimeを設定しているところに
現在より少し先の日時を設定することで、
残り時間がなくなった時の動作確認ができます。
JavaScript
1<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
2<script>
3 function setCookie(c_name, value, expiredays) {
4 // pathの指定
5 var path = location.pathname;
6 // pathをフォルダ毎に指定する場合のIE対策
7 var paths = new Array();
8 paths = path.split("/");
9 if(paths[paths.length-1] != "") {
10 paths[paths.length-1] = "";
11 path = paths.join("/");
12 }
13 // 有効期限の日付
14 var extime = new Date().getTime();
15 var cltime = new Date(extime + (60 * 60 * 24 * 1000 * expiredays));
16 var exdate = cltime.toUTCString();
17 // クッキーに保存する文字列を生成
18 var s="";
19 s += c_name +"="+ escape(value);// 値はエンコードしておく
20 s += "; path="+ path;
21 if(expiredays) {
22 s += "; expires=" +exdate+"; ";
23 }
24 else {
25 s += "; ";
26 }
27 // クッキーに保存
28 document.cookie=s;
29 }
30
31 function GetCookie(name) {
32 var result = null;
33
34 var cookieName = name + '=';
35 var allcookies = document.cookie;
36
37 var position = allcookies.indexOf( cookieName );
38 if( position != -1 ) {
39 var startIndex = position + cookieName.length;
40
41 var endIndex = allcookies.indexOf( ';', startIndex );
42 if( endIndex == -1 ) {
43 endIndex = allcookies.length;
44 }
45
46 result = decodeURIComponent(
47 allcookies.substring( startIndex, endIndex ) );
48 }
49
50 return result;
51 }
52
53 var visit_time = parseInt(GetCookie("visit_time"));
54 var startDateTime;
55
56 if(visit_time) {
57 startDateTime = new Date(visit_time);
58 }
59 else {
60 startDateTime = new Date();
61
62 // クッキーをセット
63 setCookie('visit_time', startDateTime.getTime(), 30);
64 }
65
66 function countDown() {
67 var nowDateTime = new Date();
68
69 var i=4; // 終了までの日数
70 var tmp = i*24*60*60*1000;
71
72 var endDateTime = new Date(startDateTime.getTime() + tmp);
73
74 var left = endDateTime - nowDateTime;
75 var a_day = 24 * 60 * 60 * 1000;
76
77 var d = Math.floor(left / a_day);
78
79 var h = Math.floor((left % a_day) / (60 * 60 * 1000));
80 h = ('0' + h ).slice( -2 );
81
82 var m = Math.floor((left % a_day) / (60 * 1000)) % 60;
83 m = ('0' + m ).slice( -2 );
84
85 var s = Math.floor((left % a_day) / 1000) % 60 % 60;
86 s = ('0' + s ).slice( -2 );
87
88 if(left > 0) {
89 $("#TimeLeft").html('終了まであと ' + d + '日' + h + '時間' + m + '分' + s + '秒');
90 }
91 else {
92 $("#TimeLeft").html('登録受付は終了しました。');
93 $("#form").hide();
94 }
95
96 setTimeout('countDown()', 1000);
97 }
98
99 $(function() {
100 countDown();
101 });
102</script>
html
1<div id="TimeLeft"></div>
2
3<div id="form">
4 ここに書かれた内容は、時間が来ると非表示になります。
5</div>