자주 들어가면서도 사실 정독은 하지 않는다. 그때그때 찾아보기만 할뿐..ㅋ
해서 잘 모르던걸 오늘에야 알았다.
예약 문자 보내기 개발 하는데 입력박스에는 08일 이라고 되어있는걸
parseInt 함수를 써서 썼더니 결과가 글쎄 0 이란다. 큭..
// szBookedDate = "2010-11-08";
var arrDate = szBookedDate.split( "-");
var bookedDate = new Date();
var nBookedYear = parseInt( arrDate[ 0]);
var nBookedMonth = parseInt( arrDate[ 1]);
var nBookedDate = parseInt( arrDate[ 2]);
alert( nBookedDate);
결과는 0
발췌를 해보니 아래와 같다.
parseInt(x, [radix])parseInt() supports an optional 2nd "radix" parameter to specify the base of the number to be parsed (valid range is 2-36). Entering "10" would parse the number in the familiar decimal system, while "16" would be hexadecimal. Without this parameter present, parseInt() assumesany number that begins with "0x" to be radix 16, "0" to be radix 8, and any other number to be radix 10.
뭐 내용은 대충 이렇다. 두번째 인자로 radix 를 지원한다는게 이게 뜻하는게 우리 왜 2진수, 8진수, 12진수 이거라는거다. 만약에 앞에 숫자가 0으로 들어오면 그건 8진수란다. 내가 넣은 값은..
그래..'08' 이다..죽어라고 넣어봐야 8진수로 이놈이 바꿔준거다. 그랬더니 0이 나온다더라.
뭐..사실 왜 0이 나오는지는 잘 모르겠다만, 내가 원하는것은 10진수이니 아래처럼 코드를 바꿨더니
제대로 나오더라..ㅠㅠ
// szBookedDate = "2010-11-08";var arrDate = szBookedDate.split( "-");var bookedDate = new Date();var nBookedYear = parseInt( arrDate[ 0]);var nBookedMonth = parseInt( arrDate[ 1], 10);var nBookedDate = parseInt( arrDate[ 2], 10);alert( nBookedDate);
머리가 나쁘면 수족이 고생이라고 했던가..이참에 영어공부도 열씨미 해야겠다..
바보 돌군..ㅠㅠ