javascript convert json into timestamp splits

I have a json and it have a time stamp string
What I need to do is split this string into the hour , min and second componets
Also if the Activity_time has no value something like "Activity_Time":"", how do I add a default values to the time splits

      var json = {"CustomerNum":"12345","Activity_Date":"1/24/16","Activity_Time":"06:00:00"};

      var CustNum =  json.CustomerNum
      
      var datesplit = new Date(json.Activity_Date);
      var ActivityMonth = datesplit.getMonth() + 1;
      var ActivityDay = datesplit.getDate();
      var ActivityYear = datesplit.getFullYear();
      
      // the time is pulled from Activity_time, and has a format of HH24:MI:SS
      
      var ActivityHR   = // ActivityHR  pull from the 1st char up to the 1st :    -- default to 12 to be midday
      var ActivityMIN  = // ActivityMIN pull from the 1st : up to the second : -- default to 00
      var ActivitySEC  = // ActivitySEC pull from the second : up to the end . -- default to 00
LVL 2
Jayesh AcharyaTechnichal ConsultantAsked:
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.

zephyr_hex (Megan)DeveloperCommented:
Create a date object using Activity_Date and Activity_Time, and then use getHours(), getMinutes() and getSeconds().

var json = {"CustomerNum":"12345","Activity_Date":"1/24/16","Activity_Time":"06:00:00"};

var d = new Date(json.Activity_Date + " " + json.Activity_Time);
console.log(d);
console.log(d.getHours());
console.log(d.getMinutes());
console.log(d.getSeconds());

Open in new window

1

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
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
thanks
0
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
in javascript,

I want to add a simple default

 to the json.Activity_Date
and json.Activity_Time

somthing like

var dstring = "";
var tstring = "";

if json.Activity_Date is "" then
      dstring = "01/01/3000";
else
       dstring = json.Activity_Date;
end if;

if json.Activity_Time is "" then
      tstring = "12:00:00";
else
       tstring = json.Activity_Time;
end if;

so I can then do the following line
var d = new Date(dstring + " " + tstring);
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
JavaScript

From novice to tech pro — start learning today.