Results 1 to 6 of 6

Thread: Getting Current Date in Java

  1. #1
    Join Date
    Nov 2009
    Posts
    862

    Getting Current Date in Java

    Hello, I am working on java programming. I want to create a program from which I can able to get the current date. I have tried to create a program with the help of Date class in java. But, I am not able to achieve it. If you are having any solution for getting this program or if you are having program which will provide help for creating this program then reply me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Getting Current Date in Java

    Hey, I think it is quiet simple. You just need to make use of the Calender Class in java. If you use the Calender class in java then you will able to get the following methods for your use. So, just make use of it and get your program for the Current Date in java:
    • Calendar.MONTH: If you make use of this in your program then you will able to get the month of the year value which will be in integer format.
    • Calendar.DAY: If you make use of this in your program then you will able to get the day of the month value which will be in integer format.
    • Calendar.YEAR: If you make use of this in your program then you will able to get the current year value which will be in integer format.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Getting Current Date in Java

    Hello, If you simply make use of the code below in your program then you will able to get the solution for your problem.
    Code:
    Calendar calender = new GregorianCalendar(); 
    int E = calender.get(Calendar.ERA);
    int Y = calender.get(Calendar.YEAR);
    int M = calender.get(Calendar.MONTH);
    int D = calender.get(Calendar.DAY_OF_MONTH);
    int DW = calender.get(Calendar.DAY_OF_WEEK);

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Getting Current Date in Java

    If you want to get the current Date in java then I have the following program for your use. Which will provide you current date in java.
    Code:
    import java.util.*;
    public class CurrDate
    {
      public static void main(String[] args)
    {
        Calendar calender = new GregorianCalendar();
        int Month = calender.get(Calendar.MONTH);
        int Year = calender.get(Calendar.YEAR);
        int Day = calender.get(Calendar.DAY_OF_MONTH);
        System.out.println("Current Date In Java : " + Day + "/" + (Month + 1) + "/" + Year);
      }
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Getting Current Date in Java

    You can make use of the DateUtils.now("Format")) in your program for getting different format of the date in your program. In place of the format you can simply make use of the following formats:
    • dd MMMMM yyyy
    • yyyyMMdd
    • dd.MM.yy
    • MM/dd/yy
    • yyyy.MM.dd G 'at' hh:mm:ss z
    • EEE, MMM d, ''yy
    • h:mm a
    • H:mm: ss : SSS
    • K:mm a,z
    • yyyy.MMMMM.dd GGG hh:mm aaa

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Getting Current Date in Java

    Hey, you can use the code below which will provide you formatted date and time in java. So, just make use of it and get your problem solved:
    Code:
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar; 
    public class currDateTime
     {
      public static void main(String[] args)
     { 
    	   DateFormat dFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    	   Date D = new Date();
    	   System.out.println(dFormat.format(D));
     	   Calendar calender = Calendar.getInstance();
    	   System.out.println(dFormat.format(calender.getTime()));
      }
    }

Similar Threads

  1. How to disable Current Java for Mac OS X 10.6 update 8
    By Ataa in forum Operating Systems
    Replies: 6
    Last Post: 25-04-2012, 05:19 AM
  2. Replies: 12
    Last Post: 30-03-2012, 08:21 PM
  3. MS Project 2007 Current date column
    By shoppingboy in forum Windows Software
    Replies: 3
    Last Post: 21-05-2010, 12:40 AM
  4. How to get the current month name using java program?
    By Juaquine in forum Software Development
    Replies: 4
    Last Post: 21-01-2010, 08:39 PM
  5. Formatting PWA - Current Date Line
    By kusumanabh in forum Microsoft Project
    Replies: 1
    Last Post: 14-12-2009, 11:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,573,370.86079 seconds with 17 queries