[.js] 날짜

날짜 초 분 더하기 빼기

혜화초보 2017. 9. 8. 11:08




 



<html>

<head>

</head>


<script  language="javascript"  >


function init(){


  var today = new Date();

  today.setDate(today.getDate() + 30); //Date after 30 days

  var year = today.getFullYear();

  var month = today.getMonth() + 1;

  var day = today.getDate();

  var min = '';

  var sec = '';

  console.log( year + '-' + month + '-' + day );


  today = new Date();

  today.setDate(today.getDate() - 30); // Date before 30 days

  year = today.getFullYear();

  month = today.getMonth() + 1;

  day = today.getDate();  

  console.log( year + '-' + month + '-' + day );

  

  today = new Date();  

  today.setMinutes(today.getMinutes() + 30); //After 30 minutes

  year = today.getFullYear();

  month = today.getMonth() + 1;

  day = today.getDate();    

  min = today.getMinutes();  

  console.log( year + '-' + month + '-' + day + '-' + min );  


  today = new Date();

  year = today.getFullYear();

  month = today.getMonth() + 1;

  day = today.getDate();   

  min = today.getMinutes();     

  sec = today.getSeconds();

  console.log( year + '-' + month + '-' + day + '-' + min + '-' + sec );

  

  today = new Date();

  year = today.getFullYear();

  month = today.getMonth() + 1;  

  min = today.getMinutes();      

  sec = today.setSeconds( today.getSeconds() + 500 );   //After 500 seconds

  sec = today.getSeconds();

  console.log( year + '-' + month + '-' + day + '-' + min + '-' + sec );


}


</script>

    <body  onload="init();" >

        <div id="groundDiv"  style="position:relative;"></div>

        <div id='a1'  style="position:absolute;" ></div>

        <input type='text'  size='20'       >

    </body>

</html>