How can i make a calendar with all days in one row
我已经搜索了很多这个答案,但我仍然没有找到一个合适的答案或解决这个问题的方法....
我相信很多人都这样做了,但是有人仍然没有解释他们是如何做到的,这真的很奇怪。
有没有人知道答案,用 javaScript 或 TypeScript 做这个!
How can i make a calendar with all days in one row
我们在 JQuery 库或其他一些资源中看到的大多数表格都是 7 days in 1 row table
我希望在 1 行中看到 30 天而不是日历中的 7 天!
例子---
最佳答案
简单而缓慢的方式:
var
startDate = new Date( 2015, 0, 1 )
, numOfDays = 30
, days = []
;
function addDay( date ) {
date.setDate( date.getDate() + 1 );
}
while ( numOfDays-- ) {
days.push( startDate.getDate() + '/' + ( startDate.getMonth() + 1 )
+ '/' + startDate.getFullYear() );
addDay( startDate );
}
console.log( days.join() );
控制台结果:
1/1/2015,2/1/2015,3/1/2015,4/1/2015,5/1/2015,6/1/2015,7/1/2015,8/1/2015,9/1/2015,10/1/2015,11/1/2015,12/1/2015,13/1/2015,14/1/2015,15/1/2015,16/1/2015,17/1/2015,18/1/2015,19/1/2015,20/1/2015,21/1/2015,22/1/2015,23/1/2015,24/1/2015,25/1/2015,26/1/2015,27/1/2015,28/1/2015,29/1/2015,30/1/2015
我使用计数器进行了 30 次迭代。您可以将条件更改为一个月内的几天。 但我更喜欢使用儒略日,因为它比上面的方式更快。</p>
关于javascript - 我怎样才能把所有的日子都排成一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35017433/