<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <form name="frmMain" action="" method="post"> <script language="JavaScript"> // Get from Current Date date1 = new Date(); date1.setSeconds(date1.getSeconds()+0); date1.setMinutes(date1.getMinutes()+0); date1.setHours(date1.getHours()+0); date1.setDate(date1.getDate()+0); date1.setMonth(date1.getMonth()+2); date1.setFullYear(date1.getFullYear()+0); document.write("Time = " + date1.getTime() +"<br>"); document.write("Seconds = " + date1.getSeconds() +"<br>"); document.write("Minutes = " + date1.getMinutes() +"<br>"); document.write("Hours = " + date1.getHours() +"<br>"); document.write("Day = " + date1.getDay() +"<br>"); document.write("Date = " + date1.getDate() +"<br>"); document.write("Month = " + (parseInt(date1.getMonth())+1) +"<br>"); document.write("Year = " + date1.getYear() +"<br>"); document.write("FullYear = " + date1.getFullYear() +"<br>"); document.write("<hr>") // Get from String Date date2 = new Date("08 Jun 2012 09:30:21"); date2.setSeconds(date2.getSeconds()+0); date2.setMinutes(date2.getMinutes()+0); date2.setHours(date2.getHours()+0); date2.setDate(date2.getDate()+0); date2.setMonth(date2.getMonth()+3); date2.setFullYear(date2.getFullYear()+0); document.write("Time = " + date2.getTime() +"<br>"); document.write("Seconds = " + date2.getSeconds() +"<br>"); document.write("Minutes = " + date2.getMinutes() +"<br>"); document.write("Hours = " + date2.getHours() +"<br>"); document.write("Day = " + date2.getDay() +"<br>"); document.write("Date = " + date2.getDate() +"<br>"); document.write("Month = " + (parseInt(date2.getMonth())+1) +"<br>"); document.write("Year = " + date2.getYear() +"<br>"); document.write("FullYear = " + date2.getFullYear() +"<br>"); document.write("<hr>") // AddDay function (format MM-DD-YYY) function AddDay(strDate,intNum) { sdate = new Date(strDate); sdate.setDate(sdate.getDate()+intNum); return sdate.getMonth()+1 + "-" + sdate.getDate() + "-" + sdate.getFullYear(); } document.write("AddDay = " + AddDay("06-20-2012",2) +"<br>"); document.write("<hr>") // AddMonth function (format MM-DD-YYY) function AddMonth(strDate,intNum) { sdate = new Date(strDate); sdate.setMonth(sdate.getMonth()+intNum); return sdate.getMonth()+1 + "-" + sdate.getDate() + "-" + sdate.getFullYear(); } document.write("AddMonth = " + AddMonth("06-20-2012",2) +"<br>"); document.write("<hr>") // Addyear function (format MM-DD-YYY) function AddYear(strDate,intNum) { sdate = new Date(strDate); sdate.setFullYear(sdate.getFullYear()+intNum); return sdate.getMonth()+1 + "-" + sdate.getDate() + "-" + sdate.getFullYear(); } document.write("AddYear = " + AddYear("06-20-2012",2) +"<br>"); document.write("<hr>") </script> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท