Jayesh Acharya
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","Ac tivity_Dat e":"1/24/1 6","Activi ty_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
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","Ac
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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);
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);
ASKER