日期循环

 

Js日期循环

 

var now = new Date();
var daysOfYear = [];
for (var d = new Date(2018, 0, 1); d <= now; d.setDate(d.getDate() + 1)) {
    daysOfYear.push(new Date(d));
}
 
 
shell日期循环
 

#! /bin/bash
start_date=20141012
end_date=20170930
start_sec=`date -d "$start_date" "+%s"`
end_sec=`date -d "$end_date" "+%s"`
for((i=start_sec;i<=end_sec;i+=86400)); do
    day=$(date -d "@$i" "+%Y-%m-%d")
    echo $day
done

 

 

 

pyton日期循环

 

import datetime
def main():
begin = datetime.date(2014,6,1)
end = datetime.date(2014,6,7)
for i in range((end - begin).days+1):
day = begin + datetime.timedelta(days=i)
print str(day)
if __name__ == '__main__':
main()
 

 

mongo日期循环

 

for (var i=0;i<3;i++){
var timestamp =1526140800;
var cc=db.getCollection('user_action').find({addtime:{$gte:timestamp+86400*i,$lt:timestamp+86400*(i+1)}}).count();
print(i,cc)

}

 

 

 

您可以选择一种方式赞助本站