Re: [android-developers] Re: date and time
try add follow line before format to string : date.setTime(System.currentTimeMillis()); r^ On 2 November 2011 10:44, leigh8347 leigh8...@aol.com wrote: The peice of code im using to disply the date and time is as follows datetime.toString() but like i said this does not update regards On Nov 2, 12:02 am, Lew lewbl...@gmail.com wrote: leigh8347 wrote: im [sic] making an app that writes to a .txt file and at the end of each save i want to put the date and time. this is my code that turns the time/date into a string. which works fine. SimpleDateFormat dateFormat = new SimpleDateFormat(dd/MM/ hh:mm:ss); java.util.Date date = new java.util.Date(); final String datetime = dateFormat.format(date); The problem im [sic] having is every time i save the time does not update. each row has the same time and date? Sounds like you are using the same 'datetime' reference for each save, perhaps by doing the save at the end of a longer process? It's impossible to say since the problem is in the code you have not shown. http://sscce.org/ please -- Lew -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: date and time
The date / time conversion variations you posted all seem Ok. If the issue is with how you update the file, look for a bug there, not in date formatting. -- Kostya 02.11.2011 22:59, leigh8347 пишет: Thank you but this did not work. Any other ideas regards -- 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: date and time
In this snippet, you're not re-initializing datetime to the current time, so it's going to keep the same value you assigned to it earlier (in onCreate?), no matter how many times you click the button. Oh, and rather than getBaseContext(), use your activity class.class or v.getContext(). -- Kostya 02.11.2011 23:39, leigh8347 пишет: well here is the code for file update but this seems to work fine. public void onClick(View v) { try { BufferedWriter out = new BufferedWriter(new FileWriter(/sdcard/ data_file.txt, true)); out.write(A + txtData.getText() + , + P + txtData2.getText() + , + datetime.toString()); out.write(\r\n); out.close(); Toast.makeText(getBaseContext(),Saved,Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } txtData.setText(); txtData2.setText(); } On Nov 2, 7:22 pm, Kostya Vasilyevkmans...@gmail.com wrote: The date / time conversion variations you posted all seem Ok. If the issue is with how you update the file, look for a bug there, not in date formatting. -- Kostya 02.11.2011 22:59, leigh8347 пишет: Thank you but this did not work. Any other ideas regards -- Kostya Vasilyev -- 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en