Вопрос

I have a textbox in which I show only month and year. So when I have June 2013, and when I look for First half, then I want the previous month's date to 14th of June. So in Javascript I was simply using

var currentmonth=doucument.getElementbyId("textbox");
var currentdate="01-"+currentmonth;// as earlier I had 1st to 15 of month.

I want to get the last months' last date that too in a format, like

"31-May-2013".

I am trying to change like:

currentdate= new Date(currentdate).get...//but not working
Это было полезно?

Решение

Create date object:

var currentdate = new Date("01-"+currentmonth)

Set last day of month using setFullYear, getFullYear and getMonth methods:

currentdate.setFullYear(test.getFullYear(), test.getMonth()+1, 0)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top