Results 1 to 8 of 8

Thread: java.util.Date

  1. #1
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Cool java.util.Date

    Hello to everybody , i have a problem in my project i want to make a class and the 3 of five variables is the date(month day year). i ve found the package java.util.date but i cant use straightforward the methods of the class Date. Do someone have ideas for this???

    thaks

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Java Code:
    Calendar.get(Calendar.DAY_OF_MONTH);
    Calendar.get(Calendar.DAY_OF_WEEK);
    Calendar.get(Calendar.HOUR_OF_DAY);
    Calendar.get(Calendar.MINUTE);
    Calendar.get(Calendar.MONTH);
    Calendar.get(Calendar.SECOND);
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default java.util.Date

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package ofthalmiatreio;
    import java.util.Calendar;

    /**
    *
    * @author kris
    */
    public class istorikoAsthenous {

    private String astheneia;
    private String imPathisis;
    private int day;
    private int month;
    private int year;
    private String sintagi;

    public istorikoAsthenous(){

    astheneia="NULL";
    imPathisis="null";
    sintagi="NULL";
    }

    public istorikoAsthenous(String astheneia, String imerominia, String sintagi){

    this.astheneia=astheneia;
    this.imPathisis=imerominia;
    this.sintagi=sintagi;

    }
    public void setAstheneia(String asth){

    astheneia=asth;
    }
    public String getAsteneia(){

    return astheneia;
    }
    public void setImpathisi(int day,int month,int year){

    day=Calendar.DAY_OF_MONTH;
    month=Calendar.MONTH;
    year=Calendar.YEAR;

    this.day=day;
    this.month=month;
    this.year=year;

    }
    public int getDay(){

    return day;
    }
    public int getMonth(){

    return month;
    }
    public int getYear(){

    return year;
    }
    public void setSintagi(String sint){

    sintagi=sint;
    }
    public String getSintagi(){

    return sintagi;
    }

    public void showIstoriko(){

    System.out.println("H pathisi tou asthenous einai:"+astheneia);
    System.out.println("H imerominia eksetasis einai:"+ day +"/"+ month+"/"+year);
    System.out.println("I sintagi tou giatrou:"+sintagi);
    }
    public static void main(String [] args){

    istorikoAsthenous a= new istorikoAsthenous();
    a.setAstheneia("mywpia");
    a.setImpathisi(12, 12, 2008);
    a.setSintagi("gyalia");
    a.showIstoriko();
    }

    }
    :rolleyes:

  4. #4
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    it doesn t work right the print of the date??can anyone find the mistake??

    thanks

  5. #5
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    package ofthalmiatreio;
    import java.util.Calendar;

    /**
    *
    * @author krispackage
    */
    public class istorikoAsthenous {

    private String astheneia;
    private int day;
    private int month;
    private int year;
    private String sintagi;

    public istorikoAsthenous(){

    astheneia="NULL";
    day=0;
    month=0;
    year=0;
    sintagi="NULL";
    }

    public istorikoAsthenous(String astheneia, int day, int month, int year, String sintagi){

    this.astheneia=astheneia;
    this.day=day;
    this.month=month;
    this.year=year;
    this.sintagi=sintagi;

  6. #6
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default java.util.Date

    besides 12/12/2008 it prints 2/1/5
    what the...

  7. #7
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.util.Calendar;
    
    public class IATest {
        private String astheneia;
        private String imPathisis;
        private int day;
        private int month;
        private int year;
        private String sintagi;
    
        public IATest(){
            this("", "", "");
        }
    
        public IATest(String astheneia, String imerominia, String sintagi){
            this.astheneia=astheneia;
            this.imPathisis=imerominia;
            this.sintagi=sintagi;
        }
    
        public void setAstheneia(String asth){ astheneia=asth; }
    
        public String getAsteneia(){ return astheneia; }
    
        public void setImpathisi(int day, int month, int year){
            // This initializes member variables with some unknown values.
    //        day=Calendar.DAY_OF_MONTH;
    //        month=Calendar.MONTH;
    //        year=Calendar.YEAR;
            // What are these value?
            System.out.println("DAY_OF_MONTH = " + Calendar.DAY_OF_MONTH);
            System.out.println("MONTH = " + Calendar.MONTH);
            System.out.println("YEAR = " + Calendar.YEAR);
            // They are constants of the Calendar class.
    
            // Initialize member variables with constructor argument values.
            this.day=day;
            this.month=month;
            this.year=year;
        }
    
        public int getDay(){ return day; }
    
        public int getMonth(){ return month; }
    
        public int getYear(){ return year; }
    
        public void setSintagi(String sint){ sintagi=sint; }
    
        public String getSintagi(){ return sintagi; }
    
        public void showIstoriko(){
            System.out.println("H pathisi tou asthenous einai:"+astheneia);
            System.out.println("H imerominia eksetasis einai:"+
                                day +"/"+ month+"/"+year);
            System.out.println("I sintagi tou giatrou:"+sintagi);
        }
    
        public static void main(String[] args){
            IATest a= new IATest();
            a.setAstheneia("mywpia");
            a.setImpathisi(12, 12, 2008);
            a.setSintagi("gyalia");
            a.showIstoriko();
        }
    }

  8. #8
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.util.*;
    import java.text.*;
    
    public class IATest {
        private int day;
        private int month;
        private int year;
        DateFormat customFormat =
            new SimpleDateFormat("dd MMM yyyy");
        DateFormat mediumFormat =
            DateFormat.getDateInstance(DateFormat.MEDIUM);
    
        public void setImpathisi(int day, int month, int year) {
            this.day=day;
            this.month=month;
            this.year=year;
        }
    
        public int getDay() { return day; }
    
        public int getMonth() { return month; }
    
        public int getYear() { return year; }
    
        private Date getDate() {
            Calendar calendar = Calendar.getInstance();
            int year = getYear();
            int month = getMonth(); // [0 - 11] 12 -> 0
            int day = getDay();
            calendar.set(year, month, day);
            Date date = calendar.getTime();
            return date;
        }
    
        public String getCustomFormattedDate() {
            return customFormat.format(getDate());
        }
    
        public String getMediumFormattedDate() {
            return mediumFormat.format(getDate());
        }
    
        public void showIstoriko() {
            System.out.println("H imerominia eksetasis einai:"+
                                day +"/"+ month+"/"+year);
            System.out.println("date: " + getDate());
            System.out.println("custom formatted date: " +
                                getCustomFormattedDate());
            System.out.println("medium formatted date: " +
                                getMediumFormattedDate());
        }
    
        public static void main(String[] args) {
            IATest a = new IATest();
            a.setImpathisi(12, 11, 2008);
            a.showIstoriko();
        }
    }

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 02:59 PM
  2. import java.util ????
    By kris09 in forum New To Java
    Replies: 3
    Last Post: 08-11-2008, 12:39 AM
  3. java.util.zip Question
    By acp26b in forum New To Java
    Replies: 3
    Last Post: 08-07-2008, 05:12 AM
  4. java.util
    By Java Tutorial in forum Java Tutorial
    Replies: 1
    Last Post: 02-07-2008, 01:46 PM
  5. how to use java.util.Properties?
    By christina in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 05:26 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
  •