Ho do I fix Gregorian Calender Displaying wring date


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Ho do I fix Gregorian Calender Displaying wring date

  1. #1
    Join Date
    Sep 2005
    Posts
    1

    Ho do I fix Gregorian Calender Displaying wring date

    Hi the code below will result in this being printed to screen:
    Today Year: 2005
    Today Month: 8
    Today Day: 13
    Today Hour: 8
    Today Minute: 59
    Today date: 2005-8-13

    Yet the actual date is 2005-9-13. Can anyone tell me why the month keeps comeing out wrong?

    import java.util.*;
    import java.util.Date;
    import java.text.*;
    import java.text.DateFormat;

    public class dates{
    public static void main(String[] args){
    Calendar today = Calendar.getInstance();
    System.out.println("Today Year: " + today.get(Calendar.YEAR));
    System.out.println("Today Month: " + today.get(Calendar.MONTH));
    System.out.println("Today Day: " + today.get(Calendar.DAY_OF_MONTH));
    System.out.println("Today Hour: " + today.get(Calendar.HOUR));
    System.out.println("Today Minute: " + today.get(Calendar.MINUTE));

    System.out.println("Today date: " + today.get(Calendar.YEAR)+ "-" + today.get(Calendar.MONTH) + "-" + today.get(Calendar.DAY_OF_MONTH));
    }
    }

  2. #2
    Join Date
    Aug 2004
    Posts
    46
    Calendar months are zero-indexed (e.g., January = 0, February = 1, etc.). The results you receive are correct. If you want to format the output of the date, use java.text.DateFormat and/or java.text.SimpleDateFormat.

    Formatting a Date Using a Custom Format

Similar Threads

  1. Replies: 1
    Last Post: 01-24-2003, 10:10 AM
  2. Beta 2 Date Fix?
    By Richard Curzon in forum .NET
    Replies: 2
    Last Post: 08-01-2001, 11:18 AM
  3. For any JDBC: wrap Date inside String
    By Fabio Luis De Paoli in forum Java
    Replies: 0
    Last Post: 03-03-2001, 01:12 PM
  4. Replies: 4
    Last Post: 11-27-2000, 11:12 AM
  5. date comparisons in SQL
    By Blair in forum VB Classic
    Replies: 19
    Last Post: 11-13-2000, 02:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center