• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Time refreshing

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Take look at this:



Maybe it will help you, solve your problem ;)
 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic