• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with current date and time  RSS feed

 
Birgit Steiner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I thaugth it woud be fun, if i wright a simple java code, to tell my colleagues, when my Child (Elly) is born. (This is going to be in some days)

But it has been a while since i was writing codes, so i hardly remember anything :_(

This is what i made, but it's not correct, is there a easier way to make a code, for that. Remember that this just sholud be joke for my friends, so they know the name, the date and the time of the birth.

 
John Joe
Ranch Hand
Posts: 441
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's error are you getting ?
 
Birgit Steiner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
non-static method cannot be referenced from a static context
 
Birgit Steiner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sry. "variable" not "method"for aktdat and akttime
 
John Joe
Ranch Hand
Posts: 441
3
Android Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move these code inside the main 
 
John Joe
Ranch Hand
Posts: 441
3
Android Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write like this

 
Birgit Steiner
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhhhhh!

Thank you so much, it works now. Thank you, it's great to get support that fast. Tank you!!!
 
John Joe
Ranch Hand
Posts: 441
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Birgit Steiner wrote:Ohhhhhh!

Thank you so much, it works now. Thank you, it's great to get support that fast. Tank you!!!

I'm glad it helped 
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Birgit,

welcome to the ranch, but foremost: we hope to welcome Elly in two weeks from now too!

Will you keep us informed?
 
Birgit Steiner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. I'll do so!
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you want to compare Strings for equality you should use .equals() and not ==.
e.g.

Also, because you are testing for equality (as opposed to: compareTo() >= 0) you'd have to start the program at that exact time you are testing for, otherwise nothing will happen.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:Write like this . . .
I am afraid that code contains several errors.
  • 1: Don't use the Date and Calendar classes or any of their subtypes. Use the newer Java8 Date and Time classes. REad about them in the Java™ Tutorials
  • 2: It is bad design to make everything static or to run everything in the main method.
  • 3: The really serious error: using the == operator like that will cause the program not to print, “Hello World.” I see you have been told that already.
  • 4: There are far better ways to print dates than that.

  • ...and welcome to the Ranch again
     
    Birgit Steiner
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    @Carey Brown

    thank you, yes sure i schould (have) to use .equals() :-D

    The code will never run, it's just a joke for my friends. I'll just send them the code, so they know, that my daughter is born.
     
    Campbell Ritchie
    Marshal
    Posts: 56570
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In which case she will have to hurry up and arrive today on 1st April.
     
    Birgit Steiner
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The date is just an example. When it heppened I'll change the code and then send it to my friends :-D
     
    Birgit Steiner
    Greenhorn
    Posts: 8
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Final Code, hihi. Thanks to everyone

     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!