Results 1 to 6 of 6

Thread: Get Year In Java

  1. #1
    Join Date
    Jan 2009
    Posts
    61

    Get Year In Java

    Hello, I am learning java programming language and while learning it I am quiet confused about one of the program which is given as a assignment for me. If anyone knows how to get year in java then please help me to achieve it. If you provide me help regarding it, then it will be helpful to me. So, please reply me about the same.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Get Year In Java

    Hello, I think this is quiet simple thing to do. If you want to make use of the get year in java then you simply need to make use of the code below and get your problem solved. So, just create a class and then add the below mentioned line of code in your program and get your problem solved:
    Code:
    Date date = new Date();
    int Year = date.getYear();
    System.out.println (Year);

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

    Re: Get Year In Java

    Hello, I don't know whether it is right or wrong, but if you make use of the Calender class and then make use of the object of that particular class then you will simply able to get the solution for your problem. If you use the date function then I think you will not able to get solution for it, as most of the date function are deprecated. So, just make use of the code below and get your problem solved:
    Code:
    Calendar date = Calendar.getInstance();
    int year = date.get(Calendar.YEAR);

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Get Year In Java

    Hello, I have got the code below which if you make use in your coding then you will able to get the solution which will provide you year and also you can simply make use of the formatting for that year. So, use it:
    Code:
    import java.util.*;
    import java.text.*;
    public class Year
    {
      public static void main(String[]args)
    {
      Date dt = new Date();
      SimpleDateFormat SFormat=new SimpleDateFormat("yyyy");
      System.out.println("Year: " + SFormat.format(dt));
    }
    }

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

    Re: Get Year In Java

    Hello, I have got the code below which will simply solve your problem regarding the get year in java. So, just make use of the code below and use it by understanding it:
    Code:
    import java.util.*;
    public class YearTesting
    {
      public static void main(String []args)
    {
        Calendar calender=Calendar.getInstance();
        int currYear=calender.get(Calendar.YEAR);
        System.out.println("Current Year: "+currYear );
    }
    }

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

    Re: Get Year In Java

    Hello, I think you must need to make use of the code below for getting your problem solved:
    • JavaBeans: Developing Component Software in Java
    • Java Secrets
    • Java Network Programming
    • The Java Developer's Resource
    • The Java Virtual Machine Specification

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Which are the best HTC phones for this year?
    By Oppilan in forum Portable Devices
    Replies: 4
    Last Post: 11-06-2012, 01:29 PM
  3. How to write a program to determine if year is leap year or not
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 30-11-2009, 05:21 PM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

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,716,220,803.00749 seconds with 17 queries