Link to home
Start Free TrialLog in
Avatar of Jayesh Acharya
Jayesh AcharyaFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jayesh Acharya

ASKER

thanks
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);