This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
can anybody tell me how to get current system time and date as output? i looked up the docs and found an example that requires setting timezone, using class GregorianCalendar there must be a less complicated way!
Hi Mangnesh Ofcourse , Java has a simple wayout to you problem. For accessing current Date and Time , you will have to create an object of Date class and access the date and time, like System.out.println(new java.util.Date());
and GregorianCalendar class is used to change the date format. So try out these also GregorianCalendar d1 = new GregorianCalendar(1988, 05, 06); // Jun 6 GregorianCalendar d2 = new GregorianCalendar();// today Calendar d3 = Calendar.getInstance();// today System.out.println("It was then " + d1.getTime()); System.out.println("It is now " + d2.getTime()); System.out.println("It is now " + d3.getTime()); d3.set(Calendar.YEAR, 1915); d3.set(Calendar.MONTH, Calendar.APRIL); d3.set(Calendar.DAY_OF_MONTH, 12); System.out.println("D3 set to " + d3.getTime()); SimpleDateFormat formatter = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); System.out.println("It is " + formatter.format(dNow));
all the best, vipin
Joined: Jan 17, 2003
thanx very much vipin btw i think that instead of : - System.out.println(new java.util.Date());
it should be : - System.out.println((new java.util.Date()).toString());