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
Jayesh AcharyaTechnichal ConsultantAsked:
Who is Participating?
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);

Open in new window

Jayesh AcharyaTechnichal ConsultantAuthor Commented:
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";
       dstring = json.Activity_Date;
end if;

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

so I can then do the following line
var d = new Date(dstring + " " + tstring);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.