Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 4th, 2007, 01:40 AM
Authorized User
Join Date: Aug 2005
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;
  rightNow=dd+"/"+mm+"/"+yy+" "+hh+":"+mi+":"+ss;

i'll wait 4 a good reply

Old April 20th, 2007, 01:48 AM
Friend of Wrox
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

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.


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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.