Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar class 1

Status
Not open for further replies.

DigitalOx

Programmer
Sep 29, 1998
41
US
Hello,<br>
Can someone give me a quick example of how to set the calendar to the current date. I've been searching through the docs but can't find it.<br>
<br>
Thanks,<br>
DigitalOx<br>

 
If I understand you,<br>
Date d=new Date()<br>
will make a new Date class to a variable d, and<br>
fills it the current date.<br>
Try System.out.println(new Date());<br>
Bye, Otto.
 
Hi Otto,<br>
Thanks again for helping me out again. Not only do I need the date, but I need to save it and pull it back up. In order to avoid all those deprecated date functions I did it like this: <br>
Date date = new Date();<br>
System.out.println(date);<br>
calendar.setTime(date);<br>
System.out.println(calendar.get(calendar.DAY_OF_WEEK));<br>
System.out.println(calendar.get(calendar.YEAR));<br>
<br>
Thanks<br>
DigitalOx<br>
<br>

 
Hi!<br>
<br>
Ok, try this:<br>
import java.util.Calendar;<br>
Calendar now=Calendar.getInstance();<br>
System.out.println(now.getTime());<br>
<br>
The getInstance() make a new object, and fills the time fields with the current time and date (local). See the getInstance() and getInstance(xxx, xxx).<br>
By, Otto.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top