Last active
August 29, 2015 14:04
-
-
Save setkyar/49e222a24d1daa627a03 to your computer and use it in GitHub Desktop.
JavaScript Date Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## [To get first and last day of the month in js](http://stackoverflow.com/questions/13571700/get-first-and-last-date-of-current-month-with-javascript-or-jquery) | |
var date = new Date(); | |
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1); | |
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0); | |
## For Month Select | |
function dateDropdown(select) { | |
var today = new Date(); | |
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec']; | |
var month = today.getMonth(); | |
for (var i = month; i < months.length; i++) { | |
select.options[select.options.length] = new Option(months[i] + ' '+ today.getFullYear(),months[i]); | |
}; | |
// for (i in months) { | |
// select.options[select.options.length] = new Option(months[i] + ' '+ today.getFullYear(),months[i]); | |
// }; | |
// select.options[today.getMonth()] = new Option(months[today.getMonth()]+ ' '+ today.getFullYear(), months[today.getMonth()], true, true) //select today's month | |
today.setFullYear(today.getFullYear() + 1); | |
for (i in months) { | |
if (months[i] == months[today.getMonth()]) { break; }; | |
select.options[select.options.length] = new Option(months[i] + ' '+ today.getFullYear(),months[i]); | |
}; | |
} | |
dateDropdown(document.getElementById('your-element-id')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moment JS is also nice for handling JS Dates