wood burning stoves*
The moose likes Android and the fly likes Time refreshing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Time refreshing" Watch "Time refreshing" New topic
Author

Time refreshing

Andi Dan
Greenhorn

Joined: Feb 28, 2011
Posts: 18
Hi, I have the following simple simple sample code:



Every time I run the code, in the emulator and on real device i get the time of the first run. It doesn't update.
In my opinion, every time that I run the code I should get the system time displayed and printed in the Log. This doesn't happen.
I'm new to android ... a help can be useful.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
This has nothing to do with Android, it's basic Java. "c.YEAR" is not an accessor method to retrieve the current year from c, it's a static (i.e., unchanging) number that means something entirely different. What you meant to do is c.get(Calendar.YEAR).
Andi Dan
Greenhorn

Joined: Feb 28, 2011
Posts: 18
Ok, modified the code using c.get(Calendar.x) according with year etc. and still not working. I'm getting the same time as first run.

I know they are static, the c is formed by using getInstance() instead of new (). Variables should get the values when they're initialized as a first thing.
A new instance of class is created when I start the application with the emulator.
I've changed, i put c.get and still nothing.... same values.

Has anyone have an answer?

Andi Dan
Greenhorn

Joined: Feb 28, 2011
Posts: 18
Tim Moores wrote:This has nothing to do with Android, it's basic Java. "c.YEAR" is not an accessor method to retrieve the current year from c, it's a static (i.e., unchanging) number that means something entirely different. What you meant to do is c.get(Calendar.YEAR).



no change, replaced with c.get(Calendar.YEAR) and no change, I get the same time value.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
This may sound silly, but are you certain that the app is getting updated on the device or in the emulator? What is the code you're now using?
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

Hi!

Take look at this:



Maybe it will help you, solve your problem ;)
Andi Dan
Greenhorn

Joined: Feb 28, 2011
Posts: 18
you tks, problem solved with Date date=new Date();, but not with Calendar.

Does anyone know why is not working with Calendar?
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

Hi

Date and Calendar are different class that provide different methods in each other. Better to you, will be using GregorianCalendar class, the class is not abstract like Calendar class, but is a subclass of Calendar.



GregorianCalendar object has many different methods to manipulate the date, time. You can format the myCalendar object in the same style as Date object, by SimpleDateFormat object.

Try to make in pure Java, a few examples, using GregorianCalendar class.

Bye. Sorry for my english, I'm still learning.
Andi Dan
Greenhorn

Joined: Feb 28, 2011
Posts: 18
I've stopped using Calendar and use only Date date_current = new Date(); and then date_current.getTime(); getHour(); etc.

Yes it's better to use Gregorian.

Tks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Time refreshing