javascriptdatedatejs

Get date object of last day for specific year and month, datejs


I am new to DateJs, and the http://www.datejs.com/ is 530 so I can't find documentation for each method.

I need to get the last day of specific year-month. For example :

I need the last fay of July,2015, which should be 31th,July 2015. I tried below script:

<script src="<%=application.getContextPath()%>/js/lib/datejs/date-zh-CN.js"></script>


 to=Date.today().set({year:2015,month:6}).final();//which returns Fri Jul 03 2015 00:00:00 GMT+0800 (中国标准时间) 

or

to=Date.today().set({year:2015,month:6}).final().day();//which returns Sat Jul 04 2015 00:00:00 GMT+0800 (中国标准时间)        

Which are wrong (The day I am ruining the script is at Aug 3rd, 2015). I guess I am using the method final() wrongly, but I can't get a direct example from https://github.com/datejs/Datejs .


Solution

  • Within DateJS there is an moveToLastDayOfMonth function.

    Example

    Date.july().moveToLastDayOfMonth()
    
    or,
    
    Date.today().set({year:2015,month:6}).moveToLastDayOfMonth()
    

    Hope this helps.