Come posso ottenere l'ultimo giorno del mese con la data e l'ora 11:59:59 PM?Come ottenere l'ultimo giorno del mese
risposta
Questo vi darà ultimo giorno del mese in corso.
var t= new Date();
alert(new Date(t.getFullYear(), t.getMonth() + 1, 0, 23, 59, 59));
function LastDayOfMonth(Year, Month) {
return new Date((new Date(Year, Month,1))-1);
}
Esempio:
> LastDayOfMonth(2009, 11)
Mon Nov 30 2009 23:59:59 GMT+0100 (CET)
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
Date lastDayOfMonth = cal.getTime();
Questo è un javascript strano che hai ottenuto. – droope
var d = new Date();
m = d.getMonth(); //current month
y = d.getFullYear(); //current year
alert(new Date(y,m,1)); //this is first day of current month
alert(new Date(y,m+1,0)); //this is last day of current month
Ho provato questo, e 'alert (new Date (y, m + 1,0));' ti dà l'ultimo giorno per il prossimo mese. – mickburkejnr
var d = new Date();
console.log(d);
d.setMonth(d.getMonth() + 1); // set month as next month
console.log(d);
d.setDate(0); // get the last day of previous month
console.log(d);
Qui viene emesso dal codice di cui sopra:
gio 3 ottobre 2013 11:34:59 GMT + 0100 (GMT Daylight Time)
Sun 3 Novembre 2013 11 : 34: 59 GMT + 0000 (GMT standard Time)
gio 31 ottobre, 2013 11:34:59 GMT + 0000 (GMT standard Time)
Puoi semplificarlo un po 'di più passando la data a 'setMonth' in questo modo:' d.setMonth (d.getMonth() + 1, 0) ' – Jared
Ultimo giorno del mese
now = new Date
lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, 0)
http://coffeescriptcookbook.com/chapters/dates_and_times/finding-last-day-of-the-month
var month = 1; // 1 for January
var d = new Date(2015, month, 0);
console.log(d); // last day in January
A volte tutto quello che hai è una versione di testo del mese in corso, vale a dire: aprile 2017.
//first and last of the current month
var current_month = "April 2017";
var arrMonth = current_month.split(" ");
var first_day = new Date(arrMonth[0] + " 1 " + arrMonth[1]);
//even though I already have the values, I'm using date functions to get year and month
//because month is zero-based
var last_day = new Date(first_day.getFullYear(), first_day.getMonth() + 1, 0, 23, 59, 59);
//use moment,js to format
var start = moment(first_day).format("YYYY-MM-DD");
var end = moment(last_day).format("YYYY-MM-DD");
- 1. Come ottenere il giorno del mese?
- 2. Ricevi l'ultimo giorno del mese?
- 3. L'ultimo giorno del mese sbagliato
- 4. Come trovare l'ultimo giorno del mese?
- 5. Come ottenere il primo giorno del mese corrente in PHP?
- 6. MomentJS - Come ottenere l'ultimo giorno del mese precedente dalla data?
- 7. Come posso ottenere l'ultimo giorno del mese in C#?
- 8. Come ottenere il timestamp del mese corrente, il primo giorno del mese, l'ora zero
- 9. Come trovi l'ultimo giorno del mese?
- 10. Come trasformare DateTime nell'ultimo giorno del mese?
- 11. Come si ottiene l'ultimo giorno del mese?
- 12. come ottenere il mese precedente primo giorno e il mese futuro ultimo giorno utilizzando moment.js
- 13. Ricevi prima, ultimo giorno del mese?
- 14. Primo e ultimo giorno del mese corrente
- 15. SQL - Get numerica giorno del mese/trimestre
- 16. Ottenere il primo giorno del mese in postgres
- 17. javascript data dell'ultimo giorno del mese precedente
- 18. Arrotondamento al primo giorno del mese
- 19. Ultimo giorno del mese in. NET
- 20. Ottenere il primo giorno del mese di un mese/anno specifico
- 21. Come ottenere anno/mese/giorno da un oggetto data?
- 22. Come ottenere giorno/mese e anno selezionati da jquery datepicker
- 23. giorno foreach nel mese
- 24. Formato data in giorno, mese giorno, anno
- 25. DateTime.Now.ToShortDateString(); sostituire mese e giorno
- 26. Ottenere il primo giorno in un mese da NSCalendar
- 27. ottenere giorno della settimana n-esima di mese in C#
- 28. Come trovare il primo giorno del mese successivo, se il mese corrente è dicembre
- 29. Come aggiungere giorno a DateTime alla fine del mese?
- 30. Come posso selezionare "ultimo giorno lavorativo del mese" in Panda?
Non c'è bisogno di due oggetti Date: 't.setMonths (t.getMonth() + 1, 0, 23, 59, 59 , 0) '. – RobG