Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a date object which contain current date  RSS feed

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for reading my post
maybe it is so simple for you , but it is hard for me
because i trued all methods in
java.util.date and did not found any thingthat i can use to create the date obect which automatically contain current system date.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.Calendar cal = java.util.Calendar.getInstance();
System.out.println(new java.text.SimpleDateFormat("EEEE, dd MMMM yyyy").format(cal.getTime()));
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation says

"Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond."
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API page: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html ?
The no argument constructor (new Date()) is the first thing listed!
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i ask same question about Timestamp ?
how we can initiate a timestamp with current ts ?

Thank you
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raminaa niilian:
can i ask same question about Timestamp ?
how we can initiate a timestamp with current ts ?

Thank you


Again, you should look at the javadocs to find the answer to questions like this. Please follow the link in my signature.

Layne
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or


But do check out the API docs -- they're invaluable.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adam Richards:
Err, you should make it clear that this is the new java.security.Timestamp introduced in 1.5. I'm willing to bet dollars to doughnuts that the OP wasn't thinking of this!
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, you guys sound really mean to this poor person...lol, anyways
i would do what they said, if you wanted to see the current date in a readable manner, you would do something like:

Date now= new Date()//to get a stamp of the current date
System.out.println("The current date and time is:"+now.toString());//to make it readable

hope this helps

-luc
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!