Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

javascript - Get last 6 months from in Jquery

How can I get the date range in jquery from current date, I have done following in java, need to replicate it in jquery

Datetime sixMonthsFromNow = Datetime.now().addMonths(-6);
sortByQueryString = '&fq=lastmodified:['+sixMonthsFromNow.format('yyyy-MM-dd'T'hh:mm:ss'Z'')+'+TO+NOW]';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Javascript style for this piece of code (jQuery not required) :

var now = new Date();
var sixMonthsFromNow = new Date(now.setMonth(now.getMonth() - 6));
var sortByQueryString = 
    '&fq=lastmodified:[' + sixMonthsFromNow.toISOString() + '+TO+NOW]';

// &fq=lastmodified:[2013-11-27T08:57:10.089Z+TO+NOW]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...