Thank you both for the replies! Actually, the strings are not the problem. The "human" date/time to millisecond conversions are wrong.
12/25/2011 should equal 1324789200. My converted time (from the screen output) 12/25/2011 is -877432832. And when the drill-down is done it shows that Christmas is either in 1997 or 1942. Thoughts? On Oct 16, 5:11 pm, Kostya Vasilyev <[email protected]> wrote: > The value from the JavaScript is in seconds. > > Converted to milliseconds, it does not fit in a 4-byte integer > (0x*134*_7396F480_), that's why normally longs (8 bytes) are used for > time stamps. > > You don't really need to convert the values to ints just for the sake of > a number-to-string conversion. > > Either declare smillis, smillis2 as longs and remove the typecast (to > see milliseconds): > > final*long*smillis = millis; > final*long*smillis2 = millis2; > > or divide millis and millis2 by 1000 (to see seconds): > > final int smillis = (int) (millis* / 1000L*); > final int smillis2 = (int) (millis2* / 1000L*); > > -- Kostya > > 17.10.2011 0:55, Larry/MavrickProductions ?????: > > > > > > > > > > > I am writing a program for my kids to count down to Christmas. I have > > been playing with android programming for a year, read books, look > > online for help, but this one is really got me stumped. > > > In the java, I use Time (var) .set(mm, dd, yyyy) and long millis = > > (var) .toMillis(true) to convert 12/25/2011 to milliseconds from the > > epoch. According > > tohttp://www.esqsoft.com/javascript_examples/date-to-epoch.htm, > > 12/25/2011 should equal 1324789200. But when I look at the converted > > result in the test window (I added code to show the "long" results > > before the human readable) it shows 12/25/2011 as -877432832. > > > My code is below. I'm sure that I'm missing something simple/stupid. > > Any help is greatly appreciated!! > > > Best, -Larry > > > ### CODE BELOW ### > > > package com.mavrick.countdowntester3; > > > import java.util.concurrent.TimeUnit; > > import android.app.Activity; > > import android.os.Bundle; > > import android.os.CountDownTimer; > > import android.text.format.Time; > > import android.widget.TextView; > > > public class counttime extends Activity { > > private TextView mTextField; > > private Time TimerSet; > > /** Called when the activity is first created. */ > > @Override > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > setContentView(R.layout.main); > > > final TextView mTextField = (TextView) > > findViewById(R.id.textView1); > > > Time TimerSet = new Time(); > > TimerSet.set(12, 25, 2011); // set the date to Dec 25, 2011, > > 12am > > TimerSet.normalize(true); > > long millis = TimerSet.toMillis(true); > > > Time TimeNow = new Time(); > > TimeNow.setToNow(); // set the date to Current Time > > TimeNow.normalize(true); > > long millis2 = TimeNow.toMillis(true); > > > long millisset = millis - millis2; //subtract current from > > future to set the time remaining > > > final int smillis = (int) (millis); //convert long to integer to > > display conversion results > > final int smillis2 = (int) (millis2); > > > new CountDownTimer(millisset, 1000) { > > public void onTick(long millisUntilFinished) { > > > // decompose difference into days, hours, minutes and > > seconds parts > > int weeks = (int) ((millisUntilFinished / 1000) / > > 604800); > > int days = (int) ((millisUntilFinished / 1000) / > > 86400); > > int hours = (int) (((millisUntilFinished / 1000) - > > (days > > * 86400)) / 3600); > > int minutes = (int) (((millisUntilFinished / 1000) - > > ((days > > * 86400) + (hours * 3600))) / 60); > > int seconds = (int) ((millisUntilFinished / 1000) % 60); > > int millicn = (int) (millisUntilFinished / 1000); > > > //write the data: future time, current time, remaining > > time, then human readable > > > mTextField.setText(smillis + " " + smillis2 + " > > " + > > millicn + "Time remaining: " + weeks + " " + days + " " + hours + " " > > + minutes + " " + seconds); > > } > > > public void onFinish() { > > mTextField.setText("done!"); > > } > > }.start(); > > } > > } > > -- > Kostya Vasilyev -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

