Javascript & JQuery & CSS > Javascript - ³¯Â¥/½Ã°£ °ü·Ã ÇÔ¼ö
µî·ÏÀÏ : 2017-09-08 10:18
Á¶È¸¼ö : 54,587
1. ³¯Â¥ ¿Í ½Ã°£ °ü·Ã ÇÔ¼ö.
¾Æ·¡´Â ÀÚ¹Ù½ºÅ©¸³Æ®¿¡¼ »ç¿ëµÉ ¼ö ÀÖ´Â ³¯Â¥/½Ã°£ °ü·Ã ÇÔ¼ö ÀÔ´Ï´Ù.
var systemDate = new Date()
³âµµ = systemDate.getFullYear();
´Þ = systemDate.getMonth();
ÀÏ = systemDate.getDate()
¿äÀÏ = systemDate.getDay();
½Ã°£ = systemDate.getHours();
ºÐ = systemDate.getMinutes();
ÃÊ = systemDate.getSeconds();
1/1000ÃÊ = systemDate.getMilliseconds();
getMonth() ¸¦ ÀÌ¿ëÇØ ¾ò¾î¿À´Â ´ÞÀº0~11±îÁöÀÇ ¼ýÀÚÀ̹ǷΠ1À» ´õÇØ¾ß ½ÇÁ¦ »ç¿ëÇÏ´Â ´ÞÀ» ±¸ÇÕ´Ï´Ù.
getDay() ·Î ¾ò¾î¿À´Â ¿äÀϵµ 0~6±îÁöÀÇ ¼ýÀÚÀ̹ǷΠÀÏ~Åä¿äÀÏÀÇ ¹®ÀڷΠǥÇö ÇØ¾ß ÇÕ´Ï´Ù.
2. Áö³ÁÖ ³¯Â¥ °è»ê ¿¹Á¦
var Digital = new Date();
var now_year = Digital.getFullYear(); //³â
var now_month = Digital.getMonth(); //¿ù
var now_day = Digital.getDate(); //ÀÏ
var now_date1 = Digital.getDay(); //¿äÀÏ
new_date1 = new Date(now_year,now_month,now_day-(now_date1+7));
new_date2 = new Date(now_year,now_month,now_day-(now_date1+7)+6);
now_year1 = String(new_date1.getFullYear());
now_month1 = String(new_date1.getMonth()+1);
now_day1 = String(new_date1.getDate());
now_year2 = String(new_date2.getFullYear());
now_month2 = String(new_date2.getMonth()+1);
now_day2 = String(new_date2.getDate());
alert(now_year1+":"+now_month1+":"+now_day1 + "~"+now_year2+":"+now_month2+":"+now_day2 )
3. 10ÀÏ ÈÄ ³¯Â¥¸¦ »Ì¾Æº¸ÀÚ.
var val_start="2020-05-10";
var arr1 = val_start.split('-');
var date1 = new Date(arr1[0], arr1[1], arr1[2]);
year1 = date1.getFullYear();
month1 = date1.getMonth()-1;
day1 = date1.getDate();
date2 = new Date(year1,month1,day1+10);
year2 = date2.getFullYear();
month2 = date2.getMonth()+1;
day2 = date2.getDate();
alert(year2+"-"+month2+"-"+day2);