p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > Java Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 4th, 2007, 01:40 AM
Authorized User
Points: 319, Level: 6
Points: 319, Level: 6 Points: 319, Level: 6 Points: 319, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with java.util.Date

i've a small problem in this program ... date, hours, minutes & seconds are displayed correct, but month & year are displayed incorrect ... could u plz solve this problem

import java.util.*;
class Test
{
 public static void main(String args[])
 {
  Date date=new java.util.Date();
  int dd,mm,yy,hh,mi,ss;
  String rightNow=null;
  dd=date.getDate();
  mm=date.getMonth();
  yy=date.getYear();
  hh=date.getHours();
  mi=date.getMinutes();
  ss=date.getSeconds();
  rightNow=dd+"/"+mm+"/"+yy+" "+hh+":"+mi+":"+ss;
  System.out.println(rightNow);
 }
}

i'll wait 4 a good reply

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 20th, 2007, 02:48 AM
Friend of Wrox
Points: 1,108, Level: 13
Points: 1,108, Level: 13 Points: 1,108, Level: 13 Points: 1,108, Level: 13
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
The Date class's getMonth() will give month starting from 0, i.e. 0 for Jan and so on. The getYear() method will give you the year starting from 1900 for 2007 it'll give 107.

Regards,
Rakesh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date in java hafizmuhammadmushtaq Java Basics 3 April 17th, 2008 11:37 PM
stsadm util restore exception 0x80070005 Raz Muhammad SharePoint Admin 0 July 10th, 2007 09:52 AM
Sequencial ID by date Java zaman1111 JSP Basics 7 September 24th, 2004 02:19 PM
Root Cause:java.lang.NoSuchMethodError: java.util. anees81 JSP Basics 2 January 22nd, 2004 01:49 AM
org.apache.strut.util.GenericDataSource elbicho JSP Basics 1 August 23rd, 2003 04:55 AM



All times are GMT -4. The time now is 10:53 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc