I am getting data by using a json file and one of the variable is about time, like 19:00, as GMT+0. If i would like to convert this to GMT+2, i will need to add 2, but i couldnt figure out how... I am trying to do this in a Titanium project.
Asked
Active
Viewed 387 times
0
-
Isn't json returning an ascii text value? If so, can't you just replace the +0 with a +2? – Chizl Mar 28 '13 at 20:41
-
no, the variable is just "19:00", how can i edit it so that it become "21:00" as gmt+2? – Tel4tel Mar 28 '13 at 20:46
3 Answers
1
var time = "19:00";
function incHour(t,hr){ return parseInt(hr) + 2; }
time = time.replace( /^(\d{1,2})/, incHour );

Joe Johnson
- 1,814
- 16
- 20
1
i always recommend momentjs, if you think you are going to have to do more time manipulation

Aaron Saunders
- 33,180
- 5
- 60
- 80
0
Ref: How to add 30 minutes to a JavaScript Date object?
var d1 = new Date ('6/29/2011 4:52:48 PM'),
d2 = new Date ( d1 );
d2.setHours ( d1.getHours() + 2 );
alert ( d2 );