Turn a string into a date using Rhino Java

Hi all,

Using Javascript I get a NaN:

var oldDate= '20160306 stuff stuff stuff';
var regEx = /(\d{4}\d{2}\d{2}).*/;
var match = regEx.exec(oldDate);
oldDate = match[1];

function yyyymmdd(dateIn) {
   var yyyy = dateIn.getFullYear();
   var mm = dateIn.getMonth()+1;
   var dd  = dateIn.getDate();
   return String(10000*yyyy + 100*mm + dd);
}

var today = new Date();

var dateDelta = (yyyymmdd(today) - oldDate);


Since this is working in JSfiddle but failing in Rhino I think I'd need to use Rhino Java methods to turn the oldDate string into a date object so I can get the timedelta between the oldDate and now.

How can I obtain this result?

Thanks!
LVL 1
ltpittAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
var regEx = /(\d{4})(\d{2})(\d{2}).*/;
var match = regEx.exec(oldDate);
oldDate = new Date(match[1],match[2],match[3]);

Open in new window


Isn't the above more like what you need?
0
ltpittAuthor Commented:
var int_pass_rotation = '20170302 stuff stuff stuff';
var regEx = /(\d{4}\d{2}\d{2}).*/;
var match = regEx.exec(int_pass_rotation);
var oldDate = new Date(match[1],match[2],match[3]).getTime() / 1000;

oldDate;


I've tried this and the result is NaN
0
CEHJCommented:
What is your goal - to get seconds time difference?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ltpittAuthor Commented:
I want to get the time delta in days...
0
CEHJCommented:
var dateDelta = today.getTime() - oldDate.getTime();
alert(dateDelta/1000/60/60/24 + " day(s) between");

Open in new window

0
ltpittAuthor Commented:
Not working...

The final solution was that my Rhino 1.6 date object is accepting date only in the following format:
either "Month DD, YYYY" (eg, "March 2, 2017") or an array of (YYYY, Month, DD).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ltpittAuthor Commented:
That was the working solution for me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.