time not converting into proper int to store in db

Go To StackoverFlow.com

0

I am concatenating two edittext boxes. One has date and the other has time. I then change them into a time and store them into the db. I ran the debugger and the date object seems to be correct until I convert it into an int, then it is not converting correctly. Here is my code

  Time userTime;
    userTime= new Time(date.getText().toString().concat(time.getText().toString()));

    int enteredTime = (int) ((userTime).toMillis(true) / 1000);

UpDate: For some reason all the info is going under the timezone for userTime?? Any have any ideas why

2012-04-04 21:17
by Aaron


0

int enteredTime = (int) ((userTime).toMillis(true) / 1000);

It is always better to store time in long than int. I guess it could be the reason why you are seeing wrong time.

Try something like this below:

 long enteredTime = (long) ((userTime).toMillis(true) / 1000);
2012-04-04 21:18
by kosa
No, I am still getting the same error. The year 1969 keep showing u - Aaron 2012-04-04 21:26
Are you sure date.getText().toString().concat(time.getText().toString()) is correct value? I would print this value first before passing it to Tim - kosa 2012-04-04 21:27
All the info is going into time zone for userTim - Aaron 2012-04-04 21:34


0

Where are you using the converted time? Most java code likes milliseconds rather than seconds, so try omitting the division by 1000. Be sure you use a long rather than an int in this case.

2012-04-04 21:33
by mlc
Ads