あ〜すでに忘れていた!
javaで日付
http://oshiete.goo.ne.jp/qa/7704358.html
日付文字列の変換。一昨日のことなのに。
<!DOCTYPE html> <title></title> <meta charset="UTF-8"> <body> <h1>叩かれ台</h1> <form action="#" id="test"> <p> <input type="text" name="target" value=""> <input type="button" value="+" onclick="hoge('+')"> <input type="button" value="*" onclick="hoge('*')"> <input type="button" value="-" onclick="hoge('-')"> </p> </form> <script> var ERR_MESS = '不正です'; var TARGET = document.getElementById ('test').elements['target']; function hoge (cmnd) { var value = TARGET.value; var result = null; var dateObj = null; switch (cmnd) { case '*' : result = toDateStr (addDay (new Date, 0)); break; case '-' : dateObj = dateCheck (value); if (! dateObj) { alert (ERR_MESS); return; } result = toDateStr (addDay (dateObj, -1)); break; case '+' : dateObj = dateCheck (value); if (! dateObj) { alert (ERR_MESS); return; } result = toDateStr (addDay (dateObj, 1)); break; } TARGET.value = result; } function addDay (dateObject, offsetDay) { var day = dateObject.getDate (); dateObject.setDate (day + offsetDay); return dateObject; } function toDateStr (dateObject) { var d = dateObject; return [ padding (d.getFullYear (), 4), padding (d.getMonth () + 1, 2), padding (d.getDate (), 2), '00' ].join (''); } function padding (num, z) { return ((Array (z)).join ('0') + String (num)).slice (-z); } function dateCheck (str) { var ymdx = str.match (/^(\d{4})(\d{2})(\d{2})(\d{2})$/); var result = null; if (ymdx) { result = new Date (Number (ymdx[1]), Number (ymdx[2]) - 1, Number (ymdx[3])); } return result; } </script>